0
""" how can I make it to be loop for ten times, I meant the guess input """
import random class Game: def __init__(self, game_type, release_date, game_inventor): self.game_type = game_type self.release_date = release_date self.game_inventor = game_inventor num = random.randint(0,10) guess = input("guess the number: ") print("Required guess: " +str(num)) if guess == num: print("You Won") else: print("You Lost") print("\n\n") gameType = Game("Number Guess", "29/01/2022", "MUHAMMAD") print("Game Type: " + gameType.game_type + "\n" + "Released on: " + gameType.release_date + "\n" + "Game inventor: " + gameType.game_inventor)
9 Answers
+ 3
#make use of loop
for i in range(10):
guess = input("guess the number: ")
print("Required guess: " +str(num))
if guess == num:
print("You Won")
else:
print("You Lost")
print("\n\n")
edit:
@Muhammad
convert input to
guess =int( input("guess the number: "))
+ 2
Put break after printing
print("You won")
break
+ 1
Put it in its own method and use a for loop
+ 1
Slick
Thank you so much it is really working
+ 1
Thank Jayakrishna, he provided the code
+ 1
Defaultly it takes input as string type, so you need to convert needed types..
@Muhammad
convert input to
guess =int( input("guess the number: "))
+ 1
Slick and Jayakrishna
I really appreciated your help, again am looking for your help, how can I stop the loop if it print you won otherwise continue to loops ?
0
Slick
Pls help how can I put the for loop
0
Slick
Your help again, if the guess is equal to num, it is not print("You Won"), it is printing ("You lost"), so what's wrong ?