Python Forum
What was my mistake in this Python code (easy)?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What was my mistake in this Python code (easy)?
#1
Hi everyone,

Just learning python for the first time but I am having some difficulties.

I'm having some trouble with the code below:
minGuess = 1 
maxGuess = 6

#Ask the user for their name and their maxGuess
name = input("What is your name? ")
print("Hi " + name + "!")
print("Enter a number between: " + str(minGuess) + " and " + str(maxGuess))
guess = int(input("What is your guess? ")) 

#Generate a random number and tell the user if they won or lost   
import random
secretNumber = random.randint(minGuess, maxGuess)
if (guess == "secretNumber"):
  print("Congratulations, you got it right!")
else:
  print("You lose - the number was " + str(secretNumber))
print("Thank you for playing Guess the Number.")
It won't output "Congratulations, you got it right" even if I correctly guess.
Also, I noticed that if I change the bottom bit to the code below (then I always get the output that I lost the game even when I won):

if (guess != "secretNumber"):
  print("You lose - the number was " + str(secretNumber))
else:
  print("Congratulations, you got it right!")
print("Thank you for playing Guess the Number.")
What did I do wrong? Any help would be much appreciated. Blush

Thanks,
voltman
Reply


Messages In This Thread
What was my mistake in this Python code (easy)? - by voltman - Nov-19-2019, 07:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code problem - probably easy fix? colin_dent 5 908 Jun-30-2023, 01:55 PM
Last Post: deanhystad
  [Solved] Please, help me find a simple mistake AlekseyPython 2 1,760 Jun-17-2021, 12:20 PM
Last Post: AlekseyPython
  [split] Could you please clarify where i did mistake also how run without admin right Abubakkar 1 1,799 Jun-14-2021, 09:32 AM
Last Post: Larz60+
  creating simplex tableau pivot program easy or difficult for a beginner in Python? alex_0 2 2,595 Mar-31-2021, 03:39 AM
Last Post: Larz60+
  Problem with very easy code. janekk9002 1 1,814 Dec-10-2020, 12:57 PM
Last Post: buran
  Please help to me to find my mistake in code leonardin 2 1,851 Nov-29-2020, 04:17 PM
Last Post: Larz60+
  minor mistake in code for factorial spalisetty06 2 1,896 Aug-22-2020, 05:00 PM
Last Post: spalisetty06
  Simple mistake about for Nomatter 4 2,267 Jul-16-2020, 02:24 PM
Last Post: Nomatter
  Install Mistake jlerette5 1 1,910 Feb-18-2020, 12:19 AM
Last Post: jefsummers
  countdown script not working..plz help what is mistake randyjack 1 2,123 Oct-28-2019, 06:57 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020