Jun-18-2022, 05:52 AM
(This post was last modified: Jun-19-2022, 06:56 AM by Yoriz.
Edit Reason: Added code tags
)
Code Version 1:
When Ran in Console:
When Ran in Console:
What am I doing wrong?
All I'm trying to do is get the number that is set to the
1 2 3 4 5 6 7 8 9 10 11 |
message = "Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!" print (message) amount_of_cable = input ( "Please enter the desired amount of fiberoptic cable needed for your project: " ) float (amount_of_cable) #I think I'm doing something wrong here if amount_of_cable< 100 : def multiply(amount_of_cable,b): result = int (amount_of_cable) * 0.87 return result print (multiply(amount_of_cable, 0.87 )) |
Error:Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!
Please enter the desired amount of fiberoptic cable needed for your project: 50
Traceback (most recent call last):
File "main.py", line 6, in <module>
if amount_of_cable<100:
TypeError: '<' not supported between instances of 'str' and 'int'
Code Version 2 (Attempted Solution):1 2 3 4 5 6 7 8 9 10 11 12 |
message = "Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!" print (message) amount_of_cable = int ( input ( "Please enter the desired amount of fiberoptic cable needed for your project: " )) #I think I'm doing 5. something wrong here if amount_of_cable< 100 : def multiply(amount_of_cable,b): result = int (amount_of_cable) * 0.87 return result print (multiply(amount_of_cable, 0.87 )) print (amount_of_cable, "Is this correct? Please say 'Yes, or No'" ) question = input ( "Please say Yes, or No: " ) #Test this in Replit!!! |
Output:Thank You for Choosing Robert's Fiberoptics! The One-Stop-Shop for all your fiberoptics needs!
Please enter the desired amount of fiberoptic cable needed for your project: 50
50 Is this correct? Please say 'Yes, or No'
Please say Yes, or No: Yes
No error message regarding the if statement, but it looks like it just skipped over it. What am I doing wrong?
All I'm trying to do is get the number that is set to the
amount_of_cable
variable to be recognized as less than 100, and then multiply that same number by 0.87