I began trying to learn python3 as my first programming language two days ago for a hobby and interest to teach my kids later on. I've been working on a program guessing a random number. I started with just guessing the number and built on to add two players then added a computer opponent to it as well. I would like for some constructive criticism on what i can do to improve what i have scratched together.
import random
import time
numToGuess = random.randint(1, 100)
p1NumOfGuess = 1
p2NumOfGuess = 1
c1NumOfGuess = 1
prevHigh = 100
prevLow = 1
p1 = int
p2 = int
c1 = int
print('1 or 2 Player?')
playerAmount = int(input())
if playerAmount == 1:
print('Computer Player? [Y/N]')
c1 = input()
print('Player one enter your name')
p1 = input()
else:
print('Player one enter your name')
p1 = input()
print('Player two enter your name')
p2 = input()
print('Computer Player? [Y/N]')
c1 = input()
print(p1, "Guess a Number between 1 and 100")
p1Guess = int(input())
if playerAmount == 1 and c1 != "y":
while p1Guess != numToGuess:
p1NumOfGuess += 1
if p1Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p1Guess = int(input())
elif p1Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p1Guess = int(input())
print("Congrats", p1Guess, "is correct!")
print(p1, 'took', p1NumOfGuess, 'guesses to guess correctly!')
elif playerAmount == 2 and c1 != "y":
while p1Guess != numToGuess:
p1NumOfGuess += 1
if p1Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p1Guess = int(input())
elif p1Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p1Guess = int(input())
print("Congrats", p1Guess, "is correct!")
numToGuess = random.randint(1, 100)
print(p2, "Guess a Number between 1 and 100")
p2Guess = int(input())
while p2Guess != numToGuess:
p2NumOfGuess += 1
if p2Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p2Guess = int(input())
elif p2Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p2Guess = int(input())
print("Congrats", p2Guess, "is correct!")
print(p1, 'took', p1NumOfGuess, 'guesses to guess correctly!')
print(p2, 'took', p2NumOfGuess, 'guesses to guess correctly!')
if p1NumOfGuess < p2NumOfGuess:
print(p1, 'WINS!')
elif p1NumOfGuess > p2NumOfGuess:
print(p2, 'WINS!')
else:
print('Tied Game!')
elif c1 == "y" and playerAmount == 1:
while p1Guess != numToGuess:
p1NumOfGuess += 1
if p1Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p1Guess = int(input())
elif p1Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p1Guess = int(input())
print("Congrats", p1Guess, "is correct!")
numToGuess = random.randint(1, 100)
c1Guess = random.randint(1, 100)
print('Computer is guessing')
while c1Guess != numToGuess:
c1NumOfGuess += 1
time.sleep(1.25)
if c1Guess < numToGuess:
print(c1Guess)
print("Guess is to Low!""\n""Guess Again")
prevLow = c1Guess
c1Guess = random.randint(c1Guess, prevHigh)
elif c1Guess > numToGuess:
print(c1Guess)
print("Guess is to High!""\n""Guess Again")
prevHigh = c1Guess
c1Guess = random.randint(prevLow, c1Guess)
print("Congrats", c1Guess, "is correct!")
print(p1, 'took', p1NumOfGuess, 'guesses to guess correctly!')
print('Computer took', c1NumOfGuess, 'guesses to guess correctly!')
if p1NumOfGuess < c1NumOfGuess:
print(p1, 'WINS!')
elif c1NumOfGuess < p1NumOfGuess:
print('Computer WINS!')
else:
print('Tied Game!')
elif c1 == "y" and playerAmount == 2:
while p1Guess != numToGuess:
p1NumOfGuess += 1
if p1Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p1Guess = int(input())
elif p1Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p1Guess = int(input())
print("Congrats", p1Guess, "is correct!")
numToGuess = random.randint(1, 100)
print(p2, "Guess a Number between 1 and 100")
p2Guess = int(input())
while p2Guess != numToGuess:
p2NumOfGuess += 1
if p2Guess < numToGuess:
print("Guess is to Low!""\n""Guess Again")
p2Guess = int(input())
elif p2Guess > numToGuess:
print("Guess is to High!""\n""Guess Again")
p2Guess = int(input())
print("Congrats", p2Guess, "is correct!")
numToGuess = random.randint(1, 100)
c1Guess = random.randint(1, 100)
print('Computer is guessing')
while c1Guess != numToGuess:
c1NumOfGuess += 1
time.sleep(1.25)
if c1Guess < numToGuess:
print(c1Guess)
print("Guess is to Low!""\n""Guess Again")
prevLow = c1Guess
c1Guess = random.randint(c1Guess, prevHigh)
elif c1Guess > numToGuess:
print(c1Guess)
print("Guess is to High!""\n""Guess Again")
prevHigh = c1Guess
c1Guess = random.randint(prevLow, c1Guess)
print("Congrats", c1Guess, "is correct!")
print(p1, 'took', p1NumOfGuess, 'guesses to guess correctly!')
print(p2, 'took', p2NumOfGuess, 'guesses to guess correctly!')
print('Computer took', c1NumOfGuess, 'guesses to guess correctly!')
if p1NumOfGuess < p2NumOfGuess and p1NumOfGuess < c1NumOfGuess:
print(p1, 'WINS!')
elif p2NumOfGuess < p1NumOfGuess and p2NumOfGuess < c1NumOfGuess:
print(p2, 'WINS!')
elif c1NumOfGuess < p1NumOfGuess and c1NumOfGuess < p2NumOfGuess:
print('Computer WINS!')
else:
print('Tied Game!')
else:
print('Thanks for playing!')