Lesson 2
Integer and float numbers
Last digit of integer
Statement
Given an integer number, print its last digit.a = int(input()) print(a % 10)
Tens digit
Statement
Given an integer. Print its tens digit.n = int(input()) print(n // 10 % 10)
Sum of digits
Statement
Given a three-digit number. Find the sum of its digits.n = int(input()) a = n // 100 b = n // 10 % 10 c = n % 10 print(a + b + c)
Fractional part
Statement
Given a positive real number, print its fractional part.x = float(input()) print(x - int(x))
First digit after decimal point
Statement
Given a positive real number, print its first digit to the right of the decimal point.x = float(input()) print(int(x * 10) % 10)
Car route
Statement
A car can cover distance of N kilometers per day. How many days will it take to cover a route of length M kilometers? The program gets two numbers: N and M.from math import ceil n = int(input()) m = int(input()) print(ceil(m / n))
Digital clock
Statement
Given the integer N - the number of minutes that is passed since midnight - how many hours and minutes are displayed on the 24h digital clock?The program should print two numbers: the number of hours (between 0 and 23) and the number of minutes (between 0 and 59).
For example, if N = 150, then 150 minutes have passed since midnight - i.e. now is 2:30 am. So the program should print 2 30
.
n = int(input()) hours = n // 60 minutes = n % 60 print(hours, minutes)
Total cost
Statement
A cupcake costs A dollars and B cents. Determine, how many dollars and cents should one pay for N cupcakes. A program gets three numbers: A, B, N. It should print two numbers: total cost in dollars and cents.a = int(input()) b = int(input()) n = int(input()) cost = n * (100 * a + b) print(cost // 100, cost % 100)
Clock face - 1
Statement
H hours, M minutes and S seconds are passed since the midnight (0 ≤ H < 12, 0 ≤ M < 60, 0 ≤ S < 60). Determine the angle (in degrees) of the hour hand on the clock face right now.h = int(input()) m = int(input()) s = int(input()) print(h * 30 + m * 30 / 60 + s * 30 / 3600)
Clock face - 2
Statement
Hour hand turned by α degrees since the midnight. Determine the angle by which minute hand turned since the start of the current hour. Input and output in this problems are floating-point numbers.alpha = float(input()) print(alpha % 30 * 12)
No comments:
Post a Comment