r/PythonLearning • u/Demetriazitos • 2h ago
Hi, I'm learning python. Soooo I started yesterday and I'm a little bit cofusing. I'm brazilian, but the translations of some words are here.
I'm using VS code. I started trying to do a simple calculator (only with two numbers) for undestand the inical concepts and get familiarized with python. It's my first contact with coding. Ok what is my big problem: Up to line 3, everything is working fine and I understand it. Now, I'm trying to build a calculator where the user chooses how many numbers they want to calculate. The prompt repeats based on the number of factors they entered, using for i in range(quantidade_de_fatores - 1), and I created a list that keeps appending each new number the user inputs.
Depending on the operation chosen (addition, subtraction, multiplication, or division), it should calculate all the numbers in that list:
Addition (soma): I already have sum() working to add all the values in the list.
Multiplication (multiplicação): I tried using math.prod() to multiply everything in the list, though it's showing an error.
Division (divisão) and Subtraction (subtração): I don't know what function or logic to use to calculate all the numbers in the list one after another.
I already understand the final part that displays the result. My main problem is figuring out how to properly calculate all the stored numbers in the list for subtraction, division, and multiplication.
print ("Welcome to the calculator user")
name = input ("What should I call you?")
print (f"Hello " + name)
number_of_factors = int (input (f"How many numbers does {name} want to calculate with? "))
operation = input (f"Which operation does {name} want to perform?").strip().lower()
requested_factor = float ( input ("Enter a number."))
factors_list = [requested_factor]
for i in range (number_of_factors - 1 ):
next_requested_factors = float ( input ("Enter another number."))
factors_list.append (next_requested_factors)
if operation == "addition":
result = sum(factors_list)
result = requested_factor + next_requested_factors
if operation == "division":
result = requested_factor / next_requested_factors
if operation == "subtraction":
result = num1-num2
if operation == "multiplication":
result = num1*num2
answer = input ("Show result?").strip().lower()
if answer == "yes":
print (f"{result}" )
if result==67:
print ("SIX SEVEN")
if result==39:
print ("It's Miku time!!!!!")