+ 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
39 Respuestas
+ 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
+ 4
Provide the programming language and error code or bug info.
+ 3
The code runs with out error for me.
+ 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
+ 2
Yes <?null> there are advertising threads. Please look at useful links
https://code.sololearn.com/WvG0MJq2dQ6y/?ref=app
+ 1
I run the code in IDE it runs well buth here in practice can't run well?!
+ 1
So this is for a practice in a course in the app?
If so what is the name of the topic and practice.
+ 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)
+ 1
what is the original task maybe you have to print "shipping cost: „ with a „s“ and not with „S“
+ 1
Check your indent
+ 1
He is using quotation marks.
+ 1
Sanim Mahmud can you write the correct code ?
+ 1
the correction:
weight = int(input())
def shipping_cost (weight):
print("Shipping_cost:", weight*5)
+ 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
0
I can't explain it here, do u have telegram or Instagram to send the screenshot
0
Try using quotation marks
0
Chris Coder yes it's a practice in course, Introduction python, section function, can u help me to solve it? Because there is only 3 more lesson to get Certificate