Problem Solving in the Lab

Hours = input (“Enter Hours”)
Rate = input (“Enter Rate”)

pay = float (hours * Rate)
print(pay)

I have written the above code and had tried to attach an image of the screen. I am unable to interpret the program in the jupyter. Please assist.

Hi Uday_Bora,

Please use the following code as the code you have written has some syntax errors and the variable name has to be defined exactly in order to run the code successfully like shown in the tutorial.

hours = input("Enter Hours: ")
rate = input("Enter Rate: ")
pay = float(hours) * float(rate)
print(pay)

I hope it helps.
Thanks!

1 Like

thank you. It was of certain help.

1 Like

Hi Uday,

Were you able to solve the problem?

1 Like

Yes Sir. I was. Thank you.

Now, I have a new problem. Please assist.
#Write a function with the name print_even which takes one argument n. This function should
print all even numbers starting from 0 up to but not including n.

def print_even(n):
#i=10
for i in range (0,n):
if i % 2 == 10:
#print(i)
print_even(i)

Hi, Uday.

Kindly check the logic for divisibility by 2.
if i % 2 == 10: ----> There is no number exits i whose remainder is 10 when divisible by 2.
may be a typing error for 0 instead of 10?

All the best!

1 Like

sure. I will try. Thanks.

nah…not submitting the result…for #problem #Write a function with the name print_even which takes one argument n. This function should print all even numbers starting from 0 up to but not including n.

Hi,
If your logic is correct then, it should get submitted.
Kindly restart your server from the control panel from the right hand side.
share the screenshots of the error.

All the best!

please find the code in the screeshot attached below:

You have defined the function correctly.
But you need to call the function also

try this

def print_even(n):
     for i in range (0,n):
      if i % 2 == 0:
           print(i)

print_even(4)
print_even(5)
print_even(0)

Kindly go through the lecture one more time.
Please keep a running notes with you and also check in Google for the syntax error.

1 Like