Coding Assignments ( Python Decision Making )- Problems and Solutions

Coding Assignments ( Python Decision Making )- Problems and Solutions

This article contains coding exercises related to python decision making i.e. if-elif-else statement


NOTE : The solutions are given at the last of this article. But try to write your code before taking the help of the solutions.


Problem 1) Odd or Even


Statement


Given an integer(take the value from user) , print "odd" if it's odd and print "even" otherwise.


 

Example input #1

5

 

Example output #1

odd

 

Example input #2

6

 

Example output #2

even



Problem 2) Minimum of two numbers


Statement

Given the two integers (take values from the user) , print the least of them.

 

Example input

3

7


Example output

3




Problem 3) Grade Finder


Write a program to accept marks of a student out of 100 (take value from the user) , find and display Grades ‘A’ to ‘F’ as per the following grade table using if elif else.

Marks Range Grade 

90 -100 A   

75 to 90 B 

60 to 75 C 

45 to 60 D 

33 to 45 E 

0 to 33  F 


Example input


40


Example output

E



Problem 4) Minimum of three numbers


Statement

Given three integers, print the least of them.

 

Example input

5

3

7


Example output

3




Problem 5) Equal numbers


Statement

Given three integers. Determine how many of them are equal to each other. The program must print one of the numbers: 3 (if all are the same), 2 (if two of them are equal to each other and the third one is different) or 0 (if all numbers are different).

 

Example input

10

5

10

 

Example output

2




Problem 6) Leap year


Statement

Given the year number. You need to check if this year is a leap year. If it is, print LEAP, otherwise print COMMON.

 

The rules in Gregorian calendar are as follows:

  • a year is a leap year if its number is exactly divisible by 4 and is not exactly divisible by 100
  • a year is always a leap year if its number is exactly divisible by 400

 

Example input

2012

 

Example output

LEAP




Problem 7) Largest of 3 numbers


Statement

Given three integers, print the largest of them.

 

Example input

5

3

7


Example output

7




Problem 8) Sort three numbers


Statement

 

Given three integers, print them in ascending order.

 

Example input

5

3

7

 

Example output

3 5 7




Problem 9 ) Car Route


Statement

A car can cover a 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.

 

Example input

10

25

 

Example output

3




Problem 10) Sign Function 


Statement

For the given integer X (take X from input) print 1 if it's positive, -1 if it's negative, or 0 if it's equal to zero.

 

Example input

179

 

Example output

1



Solutions

1) Odd or Even -  https://replit.com/@rhtm123/pythondecisionmaking01

2) Minimum of two numbers - https://replit.com/@rhtm123/pythondecisionmaking02

3) Grade Finder - https://replit.com/@rhtm123/pythondecisionmaking03

4) Minimum of three numbers - https://replit.com/@rhtm123/pythondecisionmaking04

5) Equal numbers - https://replit.com/@rhtm123/pythondecisionmaking05

6) Leap year -  https://replit.com/@rhtm123/pythondecisionmaking06

7) Largest of three numbers - https://replit.com/@rhtm123/pythondecisionmaking07

8) Sort three numbers - https://replit.com/@rhtm123/pythondecisionmaking08

9) Car Route - https://replit.com/@rhtm123/pythondecisionmaking09

10) Sign Function - https://replit.com/@rhtm123/pythondecisionmaking10