r/PythonLearning • • Apr 25 '26

Discussion Mon premiers ligne de code

Post image
147 Upvotes

43 comments sorted by

View all comments

1

u/ConsciousProgram1494 Apr 26 '26 edited Apr 26 '26

if you add a list like extra =['', 'really', 'no, honestly'] then loop through it...

extra =['', 'really', 'honestly'] 
for x in extra: 
   age=input(f'quel est ton age {x}: ') 
   print(f' huh! You said {age}')

Then you have a child.

extra =['', 'really', 'honestly'] 
for x in extra: 
   age=int(input(f'quel est ton age {x}: ')) 
   print(f' huh! You said {age}. I think you are {2 * age}')

Then you have a rude child.

If you change it a bit to

from random import randint

age = randint(5, 120)
guesses = 0
while True:
   guess = int(input('guess my age! '))
   guesses += 1
   if guess > age:
       print('too high')
   elif guess < age:
       print('too low')
   else:
       print(f'It only took you {guesses} guesses!')
       break  # exit the loop

You now have a game.