I was asked to create a game that makes you guess a number between 1 and 100.
So I had thes keypoints:
- If it inputs a lower number let know the user it
- If it inputs a biggernumber let know the user it
- Say in how many turns does the user won
The main function I used was the for loops to store them as a list in a variable, where later another variable will take a random item from the list:
r = []
for e in range (1,101,1):
r.append(e)
It basicly store every value of e in r as a list.
Then, I had to make the computer say the user if the nomber was bigger o lower than the number, I used two conditionals inside a while loop:
while (c != rn):
if ( c < rn ):
print (“Bigger!”)
elif ( c > rn ):
print (“Lower!”)
c = input (“Ooops, try again “)
c = int(c)
i = (i + 1)
The while is for allow the user put another values for x, the conditionals tells the user if his number was greater or lower than the number, and the counter i makes the number of turns the user took to win.
It was easy to do, and it was funny because at first, I tried to do whit a while instead a for, so I make my life easier
Pickanumber WSQ06 by charliegdrummer is licensed under a Creative Commons Attribution 4.0 International License.