-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathguessthenumber.py
More file actions
32 lines (25 loc) · 779 Bytes
/
guessthenumber.py
File metadata and controls
32 lines (25 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
import random
number = random.randint(1, 10)
tries = 1
name = input("Hello, What is your username?")
print("Hello", name + ".", )
question = input("Would you like to play a game? [Y/N] ")
if question == "n":
print("oh..okay")
if question == "y":
print("I'm thinking of a number between 1 & 10")
guess = int(input("Have a guess: "))
if guess > number:
print("Guess lower...")
if guess < number:
print("Guess higher..")
while guess != number:
tries += 1
guess = int(input("Try again: "))
if guess < number:
print("Guess Higher...")
if guess > number:
print("Guess Lower...")
if guess == number:
print("You're right! you win! The number was {0} and it only took you {1} tries".format(number, tries))