Commit bb0b56d8 authored by Fabian Benc's avatar Fabian Benc
Browse files

Added If - Else Exercises solutions.

parent a264a708
"""Input two numbers. Add those two numbers. If the result is larger than 20 print: The amount
is greater than 20, otherwise print: The amount is less than 20. """
a = int(input("Enter 1st number: "))
b = int(input("Enter 2nd number: "))
c = a + b
if c > 20:
print("The amount is greater than 20")
print("The amount is less than 20")
"""Input two numbers. If both numbers are equal, calculate the area of the square,
otherwise calculate the area of rectangle. """
a = int(input("Enter side a: "))
b = int(input("Enter side b: "))
if a == b:
p = a**2
print("Area of square is: ", p)
p = a * b
print("Area of rectangle is: ", p)
\ No newline at end of file
"""Input some word. Then check if there is “a” vowel in that word. If there is print the vowel is in the written word,
otherwise print there are no vowels. """
a = input("Enter one word: ")
if 'a' in a:
print("Vowel a is in the word: ", a)
print("This word contains no vowel/s")
\ No newline at end of file
""" Write a program to multiply two numbers in the range ending with the number 10. At the beginning of the program ask the user if he wants to multiply the numbers.
If user answers yes, enable input and multiplication.
If he answers no, enable exit out of the program. """
a = input("Do you wish to input and multiply the numbers?(type:yes/no)")
if a == 'yes':
b = int(input("Enter 1st number: "))
if b <= 10:
c = int(input("Enter 2nd number: "))
if c <= 10:
d = b * c
print("Product is: ", d)
print("Number is not in range of <=10.")
print("Number is not in range of <=10.")
print("Exiting program...")
\ No newline at end of file
"""Write a program that will allow the user to enter the sides of a triangle.
The program prints the sides of the triangle in the order in which they were entered by the user.
The program checks if such a triangle exists. If there is then it is checked whether the triangle is equilateral, isosceles or scalene.
After checking, the program prints a notification about the existence of such a triangle and the type of triangle, otherwise it prints that the triangle does not exist.
HINT: checking the existence of the geometric shape of a triangle. If the sum of the two corresponding sides is greater than the third page, then the triangle exists.
If the sum of two sides of a triangle is less than the third, it means that the triangle does not exist.
For example: a=2 b=2 c=2 => 2+2>2 meaning the triangle exists a=1 b=1 c=6 => 2+2<6 meaning the triangle does not exist"""
a = int(input("Input a: "))
b = int(input("Input b: "))
c = int(input("Input c: "))
print("First page:", a)
print("Second page:", b)
print("Third page:", c)
if a + b > c and a + c > b and b + c >a:
print("This triangle exists.")
if a == b and b != c:
if c == b and b != a:
if c == a and a != b:
if a == b and b == c:
if a != b and b != c and a != c:
print("Triangle dosen't exist.")
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment