4.13. Write Code Questions¶
Fix the errors in the code, and change it to use only one if statement. The code should print “The number is 5” when the number is 5, and should print “The number is NOT 5” when it is not.
Fix the errors in the code, and change it to use only one if statement. The code should print “The number is 5” when the number is 5, and should print “The number is NOT 5” when it is not.
-
Complete the conditional below so the word “Hi” is printed if x does not equal 3 and “Hello” is printed otherwise.
Complete the pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours, if the regular pay rate is $10 an hour. Then set
grossPay
equal to the amount an employee would be paid for working 45 hours.Complete the pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours, if the regular pay rate is $10 an hour. Then set
grossPay
equal to the amount an employee would be paid for working 45 hours.-
Rewrite your pay program using
try
andexcept
so that your program handles non-numeric input gracefully by printing a message and exiting the program. The following shows two executions of the program:Enter Hours: 20 Enter Rate: nine Error, please enter numeric input
Enter Hours: forty Error, please enter numeric input
Write the code to calculate and print the cost of a 14 mile cab ride. If the distance traveled is less than or equal to 12 miles the cost is $2.00 a mile, and if the distance traveled is more than 12 miles the cost is $1.50 a mile. Assign the final cost to the variable
total
.Write the code to calculate and print the cost of a 14 mile cab ride. If the distance traveled is less than or equal to 12 miles the cost is $2.00 a mile, and if the distance traveled is more than 12 miles the cost is $1.50 a mile. Assign the final cost to the variable
total
.-
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error message. If the score is between 0.0 and 1.0, print a grade using the following table:
Score Grade >= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F
Enter score: 0.95 A
Fix the example such that the cost of frozen yogurt is 0 if you pour exactly 1 lb. in your cup.
Fix the example such that the cost of frozen yogurt is 0 if you pour exactly 1 lb. in your cup.
-
Write a procedure that takes 2 ints, total price, and amount in wallet. Print “You have enough money” if the difference between the wallet and price is 0 or greater; otherwise, print “Get more money”.
3 criteria must be taken into account to identify leap years:
The year is evenly divisible by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year.
Write a program that takes a year as a parameter and sets
leapYear
equal toTrue
if the year is a leap year,False
otherwise. (use a few different years to test your work)3 criteria must be taken into account to identify leap years:
The year is evenly divisible by 4;
If the year can be evenly divided by 100, it is NOT a leap year, unless;
The year is also evenly divisible by 400. Then it is a leap year.
Write a program that takes a year as a parameter and sets
leapYear
equal toTrue
if the year is a leap year,False
otherwise. (use a few different years to test your work)-
Finish the following code. It first sets
n
to a number input by a user. Convert the number from a string to an integer and setresult
toTrue
if the number is an even number (evenly divisible by two) andFalse
if it is odd. Note: use the modulo operator.