Python Forum
Beginner requiring help please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner requiring help please
#2
Variable = 0 is Python. If the variable is not already defined in the current scope (read about namespaces and scope) it creates the variable, the it assigns the variable the value zero.

For a console program you can use answer = Input('Would you like to play a game?')

for the comparison there are lots of ways to compare strings depending on how strict you want to be with the input. At the very least I would allow entering 'Y', 'Yes', 'y', 'yes', 'YES'. Maybe I would allow anything that starts with an upper or lower case 'y' to be Y and everything else is N
if answer[0] in('Y', 'y'):
    # do stuff
else:
    # do other stuff
Other ways to do this involve using regular expressions (regex) or you can convert the input to upper or lower case before making the comparison.

You should look at the official python documentation. It is online here:

https://docs.python.org/3/reference/index.html

You should also familiarize yourself with the standard library:

https://docs.python.org/3/library/index.html
Reply


Messages In This Thread
Beginner requiring help please - by w4ldom4ths - Mar-27-2020, 01:36 PM
RE: Beginner requiring help please - by deanhystad - Mar-27-2020, 02:41 PM
RE: Beginner requiring help please - by perfringo - Mar-27-2020, 02:42 PM
RE: Beginner requiring help please - by w4ldom4ths - Mar-27-2020, 04:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Requiring help running an old Python script (non Python savvy user) Miletkir 13 5,963 Jan-16-2021, 10:20 PM
Last Post: Miletkir

Forum Jump:

User Panel Messages

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