Python Forum
Program: ticket_check()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Program: ticket_check()
#1
Call ticket_check() function with 2 arguments: section and seats requested and return True or False
section is a string and expects: general, floor
seats is an integer and expects: 1 - 10
Check for valid section and seats
if section is general (or use startswith "g")
if seats is 1-10 return True
if section is floor (or use starts with "f")
if seats is 1-4 return True
otherwise return False
# [ ] create and call ticket_check()

my code:
def ticket_check(section, seats):
    
    if section == "general":
        if  0 < seats < 11:
            return True
    elif section == "floor":
        if 0 < seats < 5:
            return True
    else:
        return False
sct = input("add section: ")
sts = input("add seats: ")
ticket_check(int(sct), str(sts))
I receive ValueError: Invalid literal for int() with base 10: 'general'
Do not understand this, what did I do wrong? Doh
Reply
#2
ticket_check(int(sct), str(sts))
In this line you are attempting to convert sct to an int instead of sts.

This should work fine:
ticket_check(sct, int(sts))
Reply


Forum Jump:

User Panel Messages

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