+ 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)
6 Antworten
+ 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}")
+ 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))
+ 3
Manuel Alvarado
Because you are always having a fix value which is 150 so everytime you will get same result on different inputs
0
I tried many ways, always getting errors...
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...
0
Remove + from balance