Python Exercise 4
Python Exercise 4
4
1. Write a program to change the given string to a new string with first and last letters
exchanged
# A program to take a string and swap the first and last letters
print(new_stg)
2. Write a program to display the string after deleting the nth letter from the user entered
string
stg1 = stg[0:n-1]
stg2 = stg[n+1:]
final_stg = stg1+stg2
print(f'The string after removing the {n }th letter from the string is {final_stg}')
3. Without using len() function, write a program to find the length of the string entered
# A program to find the length of the string without using len() function
length = 0
length += 1
5. Write a program that accepts a sentence from user and gives the number of words,
digits, uppercase letters and lowercase letters.
# Program to find the number of words, digits, upper case and lower case letters
7. Write a program to find the smallest integer whose factorial has 10 zeros in 1st 10 places
# A program to find the smallest number whose factorial has 10 zeros in first 10 places
for i in range(20,100):
s = str(factorial(i))
length = len(s)
if s[length-10:] == '0000000000':
break
print(i,factorial(i))