Ticker

6/recent/ticker-posts

Header Ads Widget

Contact Us For Advertisement: 9858091920

Snakify Python Program Solution Integer and Float Number

 

Tutor Chetan

Python - Programming Language

Snakify.org - Problem Solution

Integer and Float Number


1)    Last digit of integer

Statement

Given an integer number, print its last digit.

Model solution

  • a = int(input())
  • print(a % 10)


2)    Tens digit

Statement

Given an integer. Print its tens digit.

Model solution

  • n = int(input())
  • print(n // 10 % 10)


3)    Sum of digits

Statement

Given a three-digit number. Find the sum of its digits.

Model solution

  • n = int(input())
  • a = n // 100
  • b = n // 10 % 10
  • c = n % 10
  • print(a + b + c)

 

4)    Fractional part

Statement

Given a positive real number, print its fractional part.

Model solution

  • x = float(input())
  • print(x - int(x))

OR
  • # num = float(input("Enter the number: "))
  • # real = num - int(num)
  • # frac = str(round(real, 3))
  • # print(frac)

 

5)    First digit after decimal point

Statement

Given a positive real number, print its first digit to the right of the decimal point.

Model solution

  • x = float(input())
  • print(int(x * 10) % 10)

OR
  • # num = float(input("Enter the Number: "))
  • # rd = int(num*10)
  • # print(rd % 10)

 

6)    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.

Model solution

  • from math import ceil
  • n = int(input())
  • m = int(input())
  • print(ceil(m / n))

OR
  • # n = int(input("Input: "))
  • # m = int(input("Input: "))
  • # perday = m/n
  • # day = ceil(perday)
  • # print(day)

 

7)    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.

Model solution

  • n = int(input())
  • hours = n // 60
  • minutes = n % 60
  • print(hours, minutes)


8)    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.

Model solution

  • a = int(input())
  • b = int(input())
  • n = int(input())
  • cost = n * (100 * a + b)
  • print(cost // 100, cost % 100)

 

9)    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.

Model solution

  • h = int(input())
  • m = int(input())
  • s = int(input())
  • print(h * 30 + m * 30 / 60 + s * 30 / 3600)

OR
  • # hour = int(input("Input: "))
  • # minute = int(input("Input: "))
  • # second = int(input("Input: "))
  • # print((hour*3600 + minute*60 + second)/120)


Post a Comment

0 Comments