Найти тему
Soft Tech

8 September - 14 September Week 2

Оглавление

L2-Problem-1:Passed or failed

Instructions:

Write a program that outputs the message “passed” or “failed” based on user’s input. If the user enters the number in range [50,100] program must print out message “passed”, if number is in the range [0, 50) program prints out the message “failed”, otherwise program must print out “Incorrect grade!”.

Input :

Enters his/her grade.

Output :

Passed , failed or Incorrect grade!

Example:

>>> 50
Passed
>>> 15
Failed
>>> -9
Incorrect grade!

mark = int(input())
if mark >= 50 and mark <=100:
print('Passed')
elif mark <0 or mark >100:
print('Incorrect grade!')
else:
print('Failed')

L2-Problem-2: Division

Instructions:

Input:

Dividend and divisor are entered by the user on new lines.

Output:

The quotient will be printed in a new line.

Example:

>>> Enter a dividend: 63
Enter a divisor: 7
Quotient is : 9
>>> Enter a dividend: 10
Enter a divisor: 5
Quotient is : 2
>>> Enter a dividend: 5
Enter a divisor: 0
Incorrect input!

a, b = int(input()), int(input())
if b == 0 :
print('Incorrect input!')
elif a % b != 0 :
print(a // b)
elif a % b == 0:
print(int(a/b))

L2-Problem-4: Scissors-Paper-Rock

Instructions:

Write a program that imitates the two players game “Scissors-Paper-Rock”. As an input use ‘sc’ for scissors, ‘pp’ for paper and ‘rc’ for rock.

Input:

One of the three options: 'sc', 'pp' or 'rc' for each player on two separate lines.

Output:

Text message "Draw" or "Winner is user" (where user either Player1 or Player2) based on the game result.

Example 1:

Player1: sc
Player2: pp
Winner is Player1

Example 2:

Player1: rc
Player2: rc
Draw

Example 3:

Player1: pp
Player2: sc
Winner is Player2

a, b = input(), input()
if a == 'rc' and b == 'sc' or a == 'sc' and b == 'pp' or a == 'pp' and b == 'rc':
print(' Winner is Player1')
elif b == 'rc' and a == 'sc' or b == 'sc' and a == 'pp' or b == 'pp' and a == 'rc':
print(' Winner is Player2')
else:
print('Draw')

L2-Problem-5: Odd or Even

Instructions:

Write a program that asks a user to enter a number and find out if it is odd or even.

Input:

A user enters any number.

Output:

'This number is odd' or 'This number is even'.

Example:

>>>
12
This number is even
>>>
19
This number is odd 
>>>
0
0 is not odd nor even

n = int(input())
if n == 0 :
print('0 is not odd nor even')
elif n % 2 == 0 and n != 0 :
print('This number is even')
else:
print('This number is odd')

L2-Problem-6: Hello or Bye

Instructions:

Ask a user to enter a letter, if it is in the text ‘Hello World!’, then prints out “Hello”, otherwise ‘Bye’.

Input:

A user enters any single letter.

Output:

If the entered letter in 'Hello World!', it prints 'Hello' otherwise  'Bye'

Example 1:

>>>
h
Hello

Example 2:

>>>
f
Bye

n = input()
if n == 'h' or n == 'e' or n =='l' or n == 'o' or n == 'w' or n == 'r' or n =='d' or n == 'H' or n == 'E' or n =='L' or n == 'O' or n == 'W' or n == 'R' or n =='D' or n =='!':
print('Hello')
else:
print('Bye')

L2-Problem-7: Good Time of the day!

Instruction:

Write a program that asks a user for a time from 0 to 24.  If time is between 0 and 5, then prints "Good night!".If time is less than 10:00, then prints “Good morning!”. If time is less than 20:00, then prints “Good day!”, otherwise is “Good evening!”.

Input :

A user enters an integer.

Output:

According to the time, it will print messages(Good day! Good evening! Good night!)

Example:

>>>
12
Good day!
>>>
2
Good night!
>>>
-9
Not acceptable time.

n = int(input())
if 0 <= n <= 24 :
if 0 <= n <= 5:
print("Good night!")
elif 6<= n < 10 :
print('Good morning!')
elif 10 <= n < 20 :
print('Good day!')
else:
print('Good evening!')
else:
print('Not acceptable time.')

L2-Problem-8: Least Number

Instructions:

Write a program that asks a user to enter three numbers and print out the least one .

Input :

User enters three numbers a,b,c .

Output :

The program prints the least of these three numbers.

Example 1:

>>>
56
25
32
The least of these three numbers is 25

Example 2:

>>>
56
56
56
They are all equal

a, b, c = int(input()), int(input()), int(input())
if a == 4 and b == 4 and c == 4:
print('They are all equal')
elif a == b == c :
print('They are all equal')
elif a > b or b > c or c > a or a >c:
rr = min(a, b, c)
print('The least of these three numbers is ', rr)

L2-Problem-10: Triangle

Instructions:

Write a program that asks a user to enter the angles of a triangle. If the sum of three angles entered is equal to 180, then prints out “It is a valid triangle.”, otherwise "It is not a valid triangle."

Example 1:

>>>
60
80
40
It is a valid triangle.

Example 2:

>>>
90
90
0
It is not a valid triangle

a, b, c = int(input()), int(input()), int(input())
if a + b + c == 180 and a != 0 and b != 0 and c != 0:
print('It is a valid triangle.')
else:
print('It is not a valid triangle.')