Python Forum
Getting error trying to use functions to multiply numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting error trying to use functions to multiply numbers
#3
your code is incorrect
def get_user_input_1():
    user_input = input('Type a number: ')
    return user_input # here got return
 
 
def get_user_input_2():
    user_input = input('Type another number to multiply by your first number: ')
    return user_input # here also got return
 
 
def calculate_result(x, y):
    if x or y != 'q':
        x = int(x)
        y = int(y)
    result = x * y
    print(result)
 
 
get_user_input_1() # Where is the return value?
get_user_input_2() # here also
calculate_result(get_user_input_1, get_user_input_2) # get_user_input_1 and get_user_input_2 is function not variable
should be
def get_user_input_1():
    user_input = input('Type a number: ')
    return user_input
 
 
def get_user_input_2():
    user_input = input('Type another number to multiply by your first number: ')
    return user_input
 
 
def calculate_result(x, y):
    if 'q' not in (x or y):
        x = int(x)
        y = int(y)
    result = x * y
    print(result)
 
 
x = get_user_input_1()
y = get_user_input_2()
calculate_result(x, y)
Reply


Messages In This Thread
RE: Getting error trying to use functions to multiply numbers - by naughtyCat - Aug-30-2021, 05:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,167 Apr-13-2021, 10:33 AM
Last Post: deanhystad
  I want to multiply two variables, but I get an error LeqendFire 3 2,250 Aug-09-2020, 03:52 PM
Last Post: LeqendFire
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,852 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

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