It is my first time coding in python, can you please guide me. I know how to write code for everything but I am not sure how to combine division, squaring and addition in one piece of code.
Here is the task I am trying to complete:
The teacher has asked Ali to write down the age of everyone in family.
If the age is greater than 10, he should divide it by 2.
If the age is greater than 5, he will calculate the square of the age and print it.
For any other age, he should just add 1 to it.
Write a Python program that accepts the number of family members and the age of each from the user.
If the age is greater than 10, calculate and print the quotient (example: 5 / 2).
Otherwise, if the age is greater than 5, calculate and print the square (example: 5 * 5).
For other ages, just add 1 (example: 3 + 1).
Note: You must you use a loop (for or while) and an if-elif–else statement.
I have done the following so far:
age = int(input ("enter the number of member in your family:"))
while age > 10:
age /2
print ('age')
Aucun commentaire:
Enregistrer un commentaire