'int_rate =float(input('Enter the annualized interest rate in percentage:'))
what is wrong with this problem:
int_rate=float(input('Enter the annualized interest rate in percenage:')
It want let me run because it gives me an error saying that it cannot convert string into float. I'm confused
Solution 1:[1]
Python cannot convert strings directly into integers if there are any non-integer characters in the string. Your prompt about annualized interest rate percentages may make the user input a string such as "3%" which would contain the non-integer character "%."
To remedy this problem, you can try formatting the string before processing it.
input_string = input("Enter the annualized interest rate in percenage:")
int_rate = float(input_string[:-1] if input_string[-1] == "%" else input_string)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dylanweber |
