Write a Python program to find those numbers which are divisible by 7 and multiples of 5,
between 1500 and 2700 (both included).
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.")
Write a Python program to guess a number between 1 and 9.
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
numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple
count_odd = 0
count_even = 0
for x in numbers:
if not x % 2:
count_even+=1
else:
count_odd+=1
print("Number of even numbers :",count_even)
print("Number of odd numbers :",count_odd)
Write a Python program to get the Fibonacci series between 0 and 50.
Note : The Fibonacci Sequence is the series of numbers :
0, 1, 1, 2, 3, 5, 8, 13, 21, ....
Every next number is found by adding up the two numbers before it.
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.
n = int(input("Input a number: "))
# use for loop to iterate 10 times
for i in range(1,11):
print(n,'x',i,'=',n*i)
Write a Python program to get the largest number from a list.
def max_num_in_list( list ):
max = list[ 0 ]
for a in list:
if a > max:
max = a
return max
print(max_num_in_list([1, 2, -8, 0]))
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