Why still getting errors? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why still getting errors?

# Asks the user to enter the savings savings = input() # Convert the user input into a float value and update the variable savings = 150 savings = float(150) # Savings grow after 1 year at a 5% annual interest rate balance = savings * 1.05 balance = 157.5 # Convert the balance into a string and update the variable balance = str(157.5) # Concatenate the 2 strings to produce a message message = "Amount in 1 year: " +balance # Display the message print(message)

22nd Jul 2023, 4:05 AM
Manuel Alvarado
6 Answers
+ 6
Manuel Alvarado This code can be written in one line without creating a variable for saving and one for balance print(f"Amount in 1 year: {float(input())*1.05}")
22nd Jul 2023, 4:28 AM
BroFar
BroFar - avatar
+ 5
Manuel Alvarado Why are you overriding privious variable value with hardcoded value? Why not to do like this: saving = input() saving = (float) saving balance = saving * 1.05 balance = str(balance) message = "Amount in 1 year: " + balance print(message) -------- In short ------- saving = (float) input() print("Amount in 1 year: " + str(saving * 1.05))
22nd Jul 2023, 4:22 AM
A͢J
A͢J - avatar
+ 3
Manuel Alvarado Because you are always having a fix value which is 150 so everytime you will get same result on different inputs
22nd Jul 2023, 4:30 AM
A͢J
A͢J - avatar
0
I tried many ways, always getting errors...
22nd Jul 2023, 4:26 AM
Manuel Alvarado
0
I did it every way possible but still getting ok in the 1st test, 2nd and 3rd errors. Thanks anyway for your help, I will try my best...
22nd Jul 2023, 3:31 PM
Manuel Alvarado
0
Remove + from balance
23rd Jul 2023, 5:46 PM
Rohan Sharma