+ 2

I cant find bug in my code but it says that u have bug!?

weight = int(input()) def shipping_cost (weight): print("Shipping_cost:", weight*5) shipping_cost(weight) Does this code has bug ?! Helpe to solve it

24th Jul 2023, 1:30 AM
ERSHAD
ERSHAD - avatar
38 Answers
+ 5
ERSHAD the code runs fine from what I can tell as well def shipping_cost (weight): print("Shipping cost:", weight*5) weight = int(input()) shipping_cost(weight) * but you might want to remove the underscore in the print statement Chris Coder / Junior
24th Jul 2023, 2:10 AM
BroFar
BroFar - avatar
+ 5
ERSHAD thanks for providing that info. BroFar Has completed the course, Take his suggestion the underscore in the string may be the only issue.
25th Jul 2023, 8:48 PM
Chris Coder
Chris Coder - avatar
+ 4
Provide the programming language and error code or bug info.
24th Jul 2023, 1:50 AM
Chris Coder
Chris Coder - avatar
+ 4
Chris Coder Same here. There doesnt seem to be a bug. They may be doing the input wrong when they run the code or something
24th Jul 2023, 1:57 AM
Junior
Junior - avatar
+ 3
The code runs with out error for me.
24th Jul 2023, 1:55 AM
Chris Coder
Chris Coder - avatar
+ 2
Yes, your code is wrong def shipping_cost(weight): try: weight = int(weight) print("Shipping cost:", weight * 5) except ValueError: print("Invalid input. Please enter a valid weight.") input_weight = input("Enter the weight: ") shipping_cost(input_weight) This is the correct form of your code
25th Jul 2023, 12:47 PM
<?null>
<?null> - avatar
+ 2
Yes <?null> there are advertising threads. Please look at useful links https://code.sololearn.com/WvG0MJq2dQ6y/?ref=app
27th Jul 2023, 2:17 PM
BroFar
BroFar - avatar
+ 1
I run the code in IDE it runs well buth here in practice can't run well?!
24th Jul 2023, 9:12 AM
ERSHAD
ERSHAD - avatar
+ 1
ERSHAD Can you say what the bug is?
24th Jul 2023, 4:14 PM
Junior
Junior - avatar
+ 1
So this is for a practice in a course in the app? If so what is the name of the topic and practice.
25th Jul 2023, 1:44 AM
Chris Coder
Chris Coder - avatar
+ 1
Is this all the code in the program? This code has no bugs, however, if this isn’t all the code in the program you are getting the error from, the bug might be caused by something else. You should change the code so it checks if the input is numeric. That can be done with the str.isnumeric function. def shipping_cost (weight): print("Shipping_cost:", weight*5) weight = input() if weight.isnumeric(): weight = int(weight) shipping_cost(weight) else: print("invalid input: " + weight)
25th Jul 2023, 4:34 AM
TacoBlayno
TacoBlayno - avatar
+ 1
what is the original task maybe you have to print "shipping cost: „ with a „s“ and not with „S“
25th Jul 2023, 6:42 AM
Angela
Angela - avatar
+ 1
Check your indent
25th Jul 2023, 2:36 PM
Mahmoud Aslani
Mahmoud  Aslani - avatar
+ 1
He is using quotation marks.
25th Jul 2023, 4:16 PM
TacoBlayno
TacoBlayno - avatar
+ 1
Sanim Mahmud can you write the correct code ?
25th Jul 2023, 8:13 PM
ERSHAD
ERSHAD - avatar
+ 1
the correction: weight = int(input()) def shipping_cost (weight): print("Shipping_cost:", weight*5)
25th Jul 2023, 8:21 PM
Rouas Mohammed Sayah
Rouas Mohammed Sayah - avatar
+ 1
<?null> please do not spam your code in other users questions or in their codes. Please follow the forum guidelines and terms of use. https://www.sololearn.com/discuss/3021159/?ref=app
27th Jul 2023, 2:11 PM
BroFar
BroFar - avatar
0
I can't explain it here, do u have telegram or Instagram to send the screenshot
25th Jul 2023, 12:09 AM
ERSHAD
ERSHAD - avatar
25th Jul 2023, 12:10 AM
ERSHAD
ERSHAD - avatar
0
Try using quotation marks
25th Jul 2023, 3:51 PM
Sanim Mahmud