Exercises + Solution - Intro (2)
Exercises + Solution - Intro (2)
nl=[]
for x in range(1500, 2701):
if (x%7==0) and (x%5==0):
nl.append(str(x))
print (','.join(nl))
Write a Python program to convert temperatures to and from Celsius and Fahrenheit.
temp = input("Input the temperature you like to convert? (e.g., 45F, 102C
etc.) : ")
degree = int(temp[:-1])
i_convention = temp[-1]
if i_convention.upper() == "C":
result = int(round((9 * degree) / 5 + 32))
o_convention = "Fahrenheit"
elif i_convention.upper() == "F":
result = int(round((degree - 32) * 5 / 9))
o_convention = "Celsius"
else:
print("Input proper convention.")
quit()
print("The temperature in", o_convention, "is", result, "degrees.")
Note : User is prompted to enter a guess. If the user guesses wrong then the prompt appears
again until the guess is correct, on successful guess, user will get a "Well guessed!" message, and
the program will exit.
import random
target_num, guess_num = random.randint(1, 10), 0
while target_num != guess_num:
guess_num = int(input('Guess a number between 1 and 10 until you get it
right : '))
print('Well guessed!')
Write a Python program to construct the following pattern, using a nested for loop.
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
for i in range(n,0,-1):
for j in range(i):
print('* ', end="")
print('')
Write a Python program to count the number of even and odd numbers in a series of numbers
Write a Python program to get the Fibonacci series between 0 and 50.
x,y=0,1
while y<50:
print(y)
x,y = y,x+y
Write a Python program that accepts a string and calculates the number of digits and letters.
s = input("Input a string")
d=l=0
for c in s:
if c.isdigit():
d=d+1
elif c.isalpha():
l=l+1
else:
pass
print("Letters", l)
print("Digits", d)
Write a Python program to create the multiplication table (from 1 to 10) of a number.
Write a Python program to check if each number is prime in a given list of numbers. Return True
if all numbers are prime otherwise False.
Sample Data:
([0, 3, 4, 7, 9]) -> False
([3, 5, 7, 13]) -> True
([1, 5, 3]) -> False