Skip to main content

#TC1014 #WSQ06 Pick a number

1 min read

Repost for the because the other post is bugged D:

Useful links: http://stackoverflow.com/questions/5555712/generate-a-random-number 

How to use a while function in python: http://anh.cs.luc.edu/python/hands-on/3.1/handsonHtml/whilestatements.html

Code:

Rogel García a01630171

import random

value= random.randint(1,100)

tries=0

num= int(input("Guess a number from 1 to 100:"))

while num != value:

if num>value :

print (num, "is too high")

num= int(input("Try again:"))

tries=tries+1

elif num<value :

print (num, "is too low")

num= int(input("Try again:"))

tries= tries+1

tries= tries +1

print("Congratulations!, The right number is",value)

print("It took you" ,tries, "tries to win")