# Python Practice

## Solutions

``````# Question 1
print("Hello, World!")

# Question 2
name = input("Enter your name: ")
print(f"Hello, {name}!")

# Question 3
numOne = int(input("Enter first number: "))
numTwo = int(input("Enter second number: "))

print("Sum:",numOne+numTwo)
print("Difference:",numOne-numTwo)
print("Product:",numOne*numTwo)
print("Quotient:",numOne//numTwo)

# Question 4
myNumber = int(input("Enter a number: "))
if myNumber % 2 == 0:
print("Even")
else:
print("Odd")

# Question 5
age = int(input("Enter your age: "))
if age <= 12:
print("Child")
elif age <= 19:
print("Teenager")
elif age <= 59:
else:
print("Senior")

# Question 6
myList = [2,6,8,9,12]
sum = 0
for i in myList:
sum = sum + i
print(sum)

# Question 7
text = input("Enter a string: ")
count = 0
for letter in text:
if letter in "aeiouAEIOU":
count += 1
print(count)

# Question 8
myList = [3,7,8,2,5,6]

multiplier = int(input("Enter a number: "))
newList = []
for number in myList:
newList.append(number*multiplier)
print(newList)

# Question 9
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 750
a, b = 0, 1
limit = int(input("Enter the limit: "))
for i in range(limit):
print(a, end=",")
a, b = b, a+b

# Question 10
myString = input("Enter a string: ")
# print(myString[::-1])
newString = ""
for letter in myString:
newString = letter + newString
print(newString)

# Question 11
myList = [-3, 6, 5, 7, 12]

maxValue = myList[0]
for number in myList:
if number > maxValue:
maxValue = number
print(maxValue)

# minValue = myList[0]
# for number in myList:
#     if number < minValue:
#         minValue = number
# print(minValue)

# Question 12
myString = input("Enter a word: ")
if myString == myString[::-1]:
print("Yes")
else:
print("No")

# Question 13
myList = [3, 1, 4, 1, 5, 9, 2, 6]
# print(sorted(myList))
sortedList = []
while len(myList) > 0:
minValue = myList[0]
for number in myList:
if number < minValue:
minValue = number
sortedList.append(minValue)
myList.remove(minValue)

print(sortedList)

# Question 14
number = int(input("Enter a number: "))
factorial = 1
for i in range(1,number+1):
factorial = factorial * i
print(factorial)

# Question 15
myList = [4, 3, 2, 4, 9,35,99, 2, 3]
for number in myList:
if myList.count(number)==1:
print(number)

# Question 16
limit = int(input("Enter the limit: "))
for number in range(2,limit):
for i in range(2,number):
if number%i == 0:
break
else:

# Question 17
listOne = [1, 2, 3, 4, 5]
listTwo = [4, 5, 6, 7, 8]
commonItems = []

for i in listOne:
if i in listTwo:
commonItems.append(i)
print(commonItems)

# Question 18
sentence = input("Enter a sentence: ")
words = sentence.split()
print(len(words))

# Question 19
myList = [1, 2, 2, 3, 4, 4, 4, 5]
print(list(set(myList)))

# Question 20
n = int(input("Enter a number: "))
pattern = ''
for i in range(1,n+1):
pattern += str(i)
print(pattern)``````