Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

1.

s=[]

num1= int(input("Enter the lower range:"))

num1= int(input("Enter the Upper range:"))

for x in range(1500,2701):

if (x%7==0) and (x%5==0):

s.append(str(x))

print (','.join(s))

OUTPUT:

2. 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.")


OUTPUT:

3. 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!')

OUTPUT:

4. word = input("Input a word to reverse: ")

for char in range(len(word) - 1, -1, -1):

print(word[char], end="")

print("\n")

OUTPUT:
5. 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)

OUTPUT:

6. datalist = [1452, 11.23, 1 + 7j, True, 'Aniket', (0, -4), [6, 12],

{"class": 'V', "section": 'A'}]

for item in datalist:


print("Type of ", item, " is ", type(item))

OUTPUT:

7. for x in range(6):

if (x == 3 or x == 6):

continue

print(x, end=' ')

print("\n")

OUTPUT:

8. x, y = 0, 1

while y < 50:

print(y)

x, y = y, x + y
OUTPUT:

9. for fizzbuzz in range(51):

if fizzbuzz % 3 == 0 and fizzbuzz % 5 == 0:

print("fizzbuzz")

continue

elif fizzbuzz % 3 == 0:

print("fizz")

continue

elif fizzbuzz % 5 == 0:

print("buzz")

continue

print(fizzbuzz)

OUTPUT:
10. def palindrome(a):

mid = (len(a) - 1) // 2

start = 0

last = len(a) - 1

flag = 0

while (start < mid):

if (a[start] == a[last]):

start += 1

last -= 1

else:

flag = 1

break;
if flag == 0:

print("The entered string is palindrome")

else:

print("The entered string is not palindrome")

def symmetry(a):

n = len(a)

flag = 0

if n % 2:

mid = n // 2 + 1

else:

mid = n // 2

start1 = 0

start2 = mid

while (start1 < mid and start2 < n):

if (a[start1] == a[start2]):
start1 = start1 + 1

start2 = start2 + 1

else:

flag = 1

break

if flag == 0:

print("The entered string is symmetrical")

else:

print("The entered string is not symmetrical")

# Driver code

string = 'khokho'

palindrome(string)

symmetry(string)

OUTPUT:
11. str=input("Enter a word : ")

str=str.split(" ")

str.reverse()

str=" ".join(str)

print("After reverse the string =",str)

OUTPUT:

12. str = input("Enter string : ")

str = str.split(" ")

s = ""

for i in str:

l = len(i)

for j in range(l):

if (j == 0 or j == l - 1):

s = s + i[j].upper()

else:

s = s + i[j]

s=s+""

print("After 1st and last character capitilize =", s)

OUTPUT:
13. str=input("Enter string : ")

k=0

flag=0

for i in range(len(str)):

if((str[i]>='a'and str[i]<='z') or (str[i]>='A'and str[i]<='Z')):

k=1

if(str[i]>='0' and str[i]<='9'):

flag=1

if(k and flag):

print("True")

else:

print("False")

OUTPUT:

14. str=input("Enter string : ")

vowel=set("aeiouAEIOU")

count=0

for ch in str:

if ch in vowel:

count+=1
print("No. of vowels :",count)

OUTPUT:

15. str=input("Enter a sting : ")

str=str.split(" ")

print("After split =",str)

str="-".join(str)

print("After joining =",str)

OUTPUT:

You might also like