Python Tutorial
vowel or consonal
12. Write a python program to check whether an alphabet is a
vowel or consonant
l = input("Input a letter of the alphabet: ") if l in ('a','e','i','o','u'): print("%s is a vowel. " % l) elif l == 'y': print("Sometimes letter y stand for vowel, sometimes stand for consonangt.") else: print("%s is a consonant." %l)
Triangle types
11. Write a Python program to check a triangle is
equilateral, isosceles or scalene
#
Note :
#
An equilateral triangle is a triangle in which all three sides are equal.
#
A scalene triangle is a triangle that has three unequal sides.
#
An isosceles triangle is a triangle with (at least) two equal sides.
Solution:
print("Input lengths of the triangle sides: ") x = int(input("x: ")) y = int(input("y: ")) z = int(input("z: ")) if x == y == z: print("Equilateral triangle") elif x != y != z: print("Scalene triangle") else: print("isoseles triangle")
Guess Game
10. Generate random numbers between 1 and 9(including 1
and 9).
#Ask the user to guess the number, then tell them whether
they guessed too low, too high, or exactly right.
#Solutions:
import random number = random.randint(1,9) guess = 0count = 0while guess != number and guess != "exit": guess = input("What' your guess?") if guess == "exit": break guess = int(guess) count += 1 if guess < number: print("Too low!") elif guess > number: print("Too high!") else: print("You got it!") print("And it only took you",count,"tries")
Subscribe to:
Posts (Atom)