Problem 27
A ycar with 366 days is called a leap year. Leap years are necessary to kecp the calendar synchronized with the sun because the earth revolves around the sun once every \(365.25\) days. Actually, that figure is not entirely precise, and for all dates after 1582 the Gregorian correction applics. Usually years that are divisible by 4 are leap years, for example 1996 . However, years that are divisible by 100 (for example, 1900 ) are not leap years, but years that are divisible by 400 are leap years (for example, \(2000)\). Write a program that asks the user for a year and computes whether that year is a leap ycar. Use a single if statement and Boolean operators.
Problem 27
The "advanced search" feature of many search engines allows you to use Boolean operators for complex queries, such as "(cats OR dogs) AND NOT pets", Contrast these scarch operators with the Boolean operators in Python.
Problem 28
Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits \(\begin{array}{ll}\text { I } & 1 \\ \text { V } & 5 \\ \text { X } & 10 \\\ \text { L. } & 50 \\ \text { C } & 100 \\ \text { D } & 500 \\ \text { M } & 1,000\end{array}\) Numbers are formed according to the following rules: a. Only numbers up to 3,999 are represented. b. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. c. The numbers 1 to 9 are expressed \(\begin{array}{ll}\text { I } & \text { 1 } \\ \text { II } & 2 \\ \text { III } & 3 \\ \text { IV } & 4 \\ \text { V } & 5 \\ \text { VI } & 6 \\\ \text { VII } & 7 \\ \text { VIII } & 8 \\ \text { IX } & 9\end{array}\) As you can see, an I preceding a \(V\) or \(X\) is subtracted from the valuc, and you can never have more than three I's in a row. d. Tens and hundreds are done the same way, except that the letters \(\mathrm{X}, \mathrm{L}, \mathrm{C}\) and \(\mathrm{C}\), \(\mathrm{D}, \mathrm{M}\) are used instead of \(\mathrm{I}, \mathrm{V}, \mathrm{X}\), respectively. Your program should take an input, such as 1978 , and convert it to Roman numerals, MCMLXXVIII.
Problem 29
Write a program that asks the user to enter a month ( 1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print " 28 or 29 days". Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.
Problem 30
Simplify the following statements. Here, b is a variable that contains a Boolean value and \(n\) is a variable that contains an integer value. a. if \(n=0:\) \(b=\) True e1se : \(b=\) False b. If \(n=0:\) \(b=\) False e1se : \(b=\) True \(\begin{aligned} \text { c. } b=\text { False } & \\ \text { if } n &>1: \\\ \text { if } & n<2: \\ & b=\text { True } \end{aligned}\) d. if \(n<1=\) \(b=\) True \(e 1 s e:\) \(b=n>2\)
Problem 30
French country names are feminine when they end with the letter \(e\), masculine otherwise, except for the following which are masculine even though they end with e: \- Ie Belize \- le Cambodge \- le Mexique \- le Mozambique \- leZaire \- leZimbabwe Write a program that reads the French name of a country and adds the article: le for masculine or la for feminine, such as le Canada or la Belgique. However, if the country name starts with a vowel, use l'; for example, l'Afghanistan. For the following plural country names, use les: \- Ies Etats-Unis \- les Pays-Bas
Problem 31
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transaction; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts.
Problem 31
What is wrong with the following program? inputstr = input("Enter the number of quarters: ") quarters = int(inputStr) if inputstr. isdigitO: tota1 = total + puarters = \(0.25\) print ("Total; ", tota1) else : print "Input error.")
Problem 32
Write a program that reads in the name and salary of an employee. Here the salary will denote an hoserly wage, such as \(\$ 9.25\). Then ask how many hours the employee worked in the past week. Be sure to aceept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage. Print a paycheck for the employee.
Problem 33
When you use an automated teller machine (A'TM) with your bank card, you need to use a personal identification number (PIN) to access your account. If a user fails more than three times when entering the PIN, the machine will block the card. Assume that the user's PIN is " \(1234^{\prime \prime}\) and write a program that asks the user for the PIN no more than three times, and does the following: \- If the user enters the right number, print a message saying, "Your PIN is correct", and end the program. \- If the user enters a wrong number, print a message saying, "Your PIN is incorrect" and, if you have asked for the PIN less than three times, ask for it again. \- If the user enters a wrong number three times, print a message saying "Your bank card is blocked" and end the program.