question 1)
Answer:
gender=input("Input gender: ")
age=int(input("Input age: "))
if(gender=="male" and age>=18):
print("Old enough for army")
else:
print("Not old enough for army")
question 2)
Answer:
groups =["swe234", "ddf160", "bty123", "Ptr223"]
group=input("Input group: ")
if(group in groups):
print("Group is: "+group)
else:
print("Group C")
question 3)
Answer:
for i in range(15,21):
print(i,end=" ")
print()
for i in range(10,0,-1):
print(i,end=" ")
print()
for i in range(2,21):
print(i,end=" ")
print()
for i in range(1,11):
print(i,end=" ")
question 4-8)
Answer:
sumEvens=0
sumOdds=0
maxNumber=0
minNumber=1000000
for i in range(0,5):
number=int(input("Enter number: "))
if number %2==0:
sumEvens+=number
else:
sumOdds+=number
if number>maxNumber:
maxNumber=number
if number<minNumber:
minNumber=number
print(f"Sum of the evens: {sumEvens}")
print(f"Sum of the odds: {sumOdds}")
print(f"The max: {maxNumber}")
print(f"The min: {minNumber}")
Comments
Leave a comment