Python Forum
TypeError: can't multiply sequence by non-int of type 'str'
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: can't multiply sequence by non-int of type 'str'
#11
When I add int to both cost[0] * cost[1], the code repeats itself and never multiplies them. Why is this happening?
1
2
def Pass_Calculate(cost):
    return int(cost[0]) * int(cost[1])
Reply
#12
When does 'Pass_Total()' come into play?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#13
Pass_Total() comes into play after Pass_Discount()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
 def Pass_Show():
    print("Aussie Pass!")
    print("Please select a package and discount depending on age.")
    print("E.g. Package = 7")
    Pass_Package()
 
def Pass_Package():
    print("7 Day Pass – $139.95")
    print("14 Day Pass - $239.95")
    print("30 Day Pass - $500.00")
    Pass_Discount()
 
def Pass_Discount():
    print("Children (Under 15) - 60% off")
    print("Students (Over 15 & less than 22) - 40% off")
    print("Seniors (60 or over) - 50% off")
    Pass_Total()
 
def Pass_Total():
    cost = Pass_Cost()
    total = Pass_Calculate(cost)
    print("The total cost is: $" + str(total))
 
def Pass_Cost():#User inputs the type of package they suit and discount
    cost=list()
    package = input('Package: ')
    if package == '7' or '14' or '30': #If they enter those values they will move onto choosing their discount
        print("Proceed...")
        cost.append(package)
         
    if package not in('7','14','30'):
        Pass_Cost()#If they do not enter any of those values they will be prompted to ask again
     
    p = int(package)
 
 
    discount = input("Discount: ")    
    if discount == "Children":
        discount = 0.60
        cost.append(discount)
        Pass_Calculate(cost)
    if discount == "Students":
        discount = 0.50
        cost.append(discount)
        Pass_Calculate(cost)
    if discount == "Seniors":
        discount = 0.40
        cost.append(discount)
        Pass_Calculate(cost)
    if discount not in ("Children","Students","Seniors"):
        Pass_Cost()
 
    d = int(discount)
     
    return p, d
     
     
def Pass_Calculate(cost):
    return float(int(cost[0])) * float(int(cost[1])) #Calculates the cost from their chosen package and discount e.g. 7 * 0.6
                    #7 being the chosen package (7 Day Pass) and 0.6 being the Children discount (60%)
 
 
 
 
Pass_Show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: unsupported operand type(s) for /: 'str' and 'int' enderfran2006 1 3,909 Oct-01-2020, 09:41 AM
Last Post: buran
  TypeError: can't multiply sequence by non-int of type 'complex' FeverDream 2 14,589 Jul-12-2018, 11:08 PM
Last Post: DeaD_EyE
  TypeError: can't multiply sequence by non-int of type 'str' rmpadilla73 4 31,921 May-28-2018, 12:21 AM
Last Post: py_learner
  I can't multiply within my code TypicalBrummie 1 3,156 Feb-06-2018, 08:05 PM
Last Post: boring_accountant
  python!TypeError: can't multiply sequence by non-int of type 'float' shaywune 2 10,737 Sep-24-2016, 04:33 PM
Last Post: shaywune

Forum Jump:

User Panel Messages

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