Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question with Code
#1
Hi, why is my code; "str(input('Enter a plan: ; plan)) giving me a syntax error? I thought this syntax is perfectly legal in Python.

plan = 'M' # ‘M’ = monthly, ‘D’ = daily
plan = 'D'
xplan = str(input('Enter plan: ' plan))
hours = 4
student = False
senior = False
total = 0

# write the code to calculate the total below
if xplan == 'M':
  basefee = 30
  discount = 10/100
  hourlyfee = 3
  basehour = 30
  extrahours = hours - basehour
  extrafee = extrahours*hourlyfee
  totalfee = basefee + extrafee
  
  if student == True and hours > 30:
    discountedcost = (totalfee)*discount
    totalcost = totalfee - discountedcost
    print(totalcost)
    
  elif hours < 30:
    totalfee = totalfee - extrafee
    print(totalfee)

elif xplan == 'D':
  if hours < 4 and student == False and senior == False:
    totalfee = 10* hours
    print(totalfee)
  
  elif hours > 4 and student == True and senior == True:
    totalfee = (8*hours)*0.10
    print(totalfee)
Reply
#2
xplan = input('Enter plan: ')
don't need to cast to string, it's the default.
Reply
#3
Line 3 is not correct. You can't just put two values next to each other (as in 'Enter plan: ' plan). Perhaps that's a typo?

Also, do you realise that line 2 overwrites the value in plan that you assigned in line 1?
Reply
#4
Okay, thank you for the suggestion and pointing out my mistakes.
Reply
#5
(Nov-13-2019, 12:30 AM)Than999 Wrote: Hi, why is my code; "str(input('Enter a plan: ; plan)) giving me a syntax error? I thought this syntax is perfectly legal in Python.

plan = 'M' # ‘M’ = monthly, ‘D’ = daily
plan = 'D'
xplan = str(input('Enter plan: ' plan))
hours = 4
student = False
senior = False
total = 0

# write the code to calculate the total below
if xplan == 'M':
  basefee = 30
  discount = 10/100
  hourlyfee = 3
  basehour = 30
  extrahours = hours - basehour
  extrafee = extrahours*hourlyfee
  totalfee = basefee + extrafee
  
  if student == True and hours > 30:
    discountedcost = (totalfee)*discount
    totalcost = totalfee - discountedcost
    print(totalcost)
    
  elif hours < 30:
    totalfee = totalfee - extrafee
    print(totalfee)

elif xplan == 'D':
  if hours < 4 and student == False and senior == False:
    totalfee = 10* hours
    print(totalfee)
  
  elif hours > 4 and student == True and senior == True:
    totalfee = (8*hours)*0.10
    print(totalfee)

The logic is bit not clear. You want to get the input for "plan" from user? or you want to define in the script itself? You can choose one of another, not both
Reply


Forum Jump:

User Panel Messages

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