Okay so I have a problem that will probably be very very simple for most of the python coders on here to do, but I am in an intro to computer programming class and am doing pretty good, but I am lost on this one problem. I hope you can take a few minutes to help me because I will love you for it! Here is the problem:
Write a program the user for hours and rate per hour using raw_input to compute gross pay. Use 40 hours and a rate of 15.00 per hour to test the program (the pay should be 600). You should use raw_input to read a string and float() to convert the string to a number. Do not worry about error checking or bad user data.
#This first line is provided for you
hrs = raw_input("Enter Hours:")
This is what I attempted doing so far:
hrs = raw_input(“Enter Hours:”)
rate = 15
pay = hrs * rate
print pay
I know its wrong because I didn't include float(), but I have no idea what that is and how it would play a part into my code. Here is what I attempted, and it came up error but the instructions said that its okay for that to happen. Any help on what I'm supposed to do would be greatly appreciated!!
3 Replies - 651 Views - Last Post: 17 November 2015 - 11:39 PM
#1
Help with simply programming assignment for class?
Posted 17 November 2015 - 07:50 PM
Replies To: Help with simply programming assignment for class?
#2
Re: Help with simply programming assignment for class?
Posted 17 November 2015 - 08:15 PM
https://docs.python....ions.html#float
If you read this doc, it mentions that you pass a string to the constructor. What did you try? What was the error? Given that information, it should be pretty simple to complete your program.
If you read this doc, it mentions that you pass a string to the constructor. What did you try? What was the error? Given that information, it should be pretty simple to complete your program.
#3
Re: Help with simply programming assignment for class?
Posted 17 November 2015 - 11:24 PM
The instructions tell you where to use float(), but to make it a bit clearer, the way to think about this is: you need a value for hrs that is numeric. raw_input() gives you a string, so how can you convert that string to a number?
#4
Re: Help with simply programming assignment for class?
Posted 17 November 2015 - 11:39 PM
Quote
I know its wrong because I didn't include float(), but I have no idea what that is ..
If you don't know what it is then you look it up. xclite has provided you with a link, but presumably you also have some reference materials.
Quote
and it came up error but the instructions said that its okay for that to happen.
The instructions don't say to ignore errors but to "not worry about error checking or bad user data". This means that you assume that the user will enter a number if a number is required.
Page 1 of 1

New Topic/Question
Reply


MultiQuote




|