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)

29th Jan 2022, 3:25 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
9 Réponses
+ 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: "))
29th Jan 2022, 3:30 PM
Jayakrishna 🇮🇳
+ 2
Put break after printing print("You won") break
29th Jan 2022, 4:04 PM
Jayakrishna 🇮🇳
+ 1
Put it in its own method and use a for loop
29th Jan 2022, 3:29 PM
Slick
Slick - avatar
+ 1
Slick Thank you so much it is really working
29th Jan 2022, 3:34 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
+ 1
Thank Jayakrishna, he provided the code
29th Jan 2022, 3:34 PM
Slick
Slick - avatar
+ 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: "))
29th Jan 2022, 3:51 PM
Jayakrishna 🇮🇳
+ 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 ?
29th Jan 2022, 4:00 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
0
Slick Pls help how can I put the for loop
29th Jan 2022, 3:30 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar
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 ?
29th Jan 2022, 3:38 PM
Muhammad Abdulmalik
Muhammad Abdulmalik - avatar