Python Forum
Program: ticket_check() - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Program: ticket_check() (/thread-7619.html)



Program: ticket_check() - Truman - Jan-17-2018

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


RE: Program: ticket_check() - Mekire - Jan-18-2018

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))