random number guessing game python

Solutions on MaxInterview for random number guessing game python by the best coders in the world

showing results for - "random number guessing game python"
Laura
19 Mar 2019
1import random
2print("Welcome to random number gusser game")
3print("I will guss number from 1 to 100 ")
4Difficulty = str(input("What is your difficulty Easy or hard:- ")).lower()
5def difficiulty(Difficulty):
6    random_number = random.randint(1,100)
7    if Difficulty == "easy":
8        print("you will get 10 chances")
9        chances = 10
10        while True:
11            number_choosen = int(input("Guss the number now:- "))
12            if number_choosen != random_number:
13                chances -= 1
14                if chances == 0:
15                    return "You Lost"
16                    break
17                else:
18                    print("Not correct number")
19            else:
20                return "you won"
21    elif Difficulty == "hard":
22        chances = 5
23        print("You will get 5 chances")
24        while True:
25            number_choosen = int(input("Guss the number now:- "))
26            if number_choosen != random_number:
27                chances -= 1
28                if chances == 0:
29                    return "You Lost"
30            else:
31                return "You Won"
32print(difficiulty(Difficulty))