uaveiro-leci/1ano/1semestre/fp/aula04/hilo.py

29 lines
690 B
Python
Raw Permalink Normal View History

2022-10-14 22:03:25 +00:00
# Complete the code to make the HiLo game...
import random
2022-10-14 22:03:25 +00:00
def main():
# Pick a random number between 1 and 100, inclusive
secret = random.randrange(1, 101)
print("Can you guess my secret?")
# put your code here
c = 0
2022-10-18 17:18:56 +00:00
trieslist = []
2022-10-14 22:03:25 +00:00
num = -1
while secret != num:
num = int(input('>>> '))
if num > secret:
print('High')
if num < secret:
print('Low')
c += 1
2022-10-18 17:18:56 +00:00
trieslist.append(str(num))
triesstr = ', '.join(trieslist)
print(
f'Well done! The secret number was {secret}. It took you {c} tries to get it right.\nList of tries: {triesstr}')
2022-10-14 22:03:25 +00:00
2022-10-18 17:18:56 +00:00
if __name__ == "__main__":
main()