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

1.

Write a python program to print ‘n’ number

number = int(input("Please Enter any Number: "))

for i in range(1, number + 1):

print (i, end = ' ')

2. Write a python program to sort 12,-9,6,8 and -100

lst = []

# number of elements as input

n = int(input("Enter number of elements : "))

# iterating till the range

for i in range(0, n):

ele = int(input())

# adding the element

lst.append(ele)

lst.sort()

print(lst)

3. Python program to convert 145 days to months and days

number_of_days = int(input("Enter number of days: "))


years = number_of_days // 365
months = (number_of_days - years *365) // 30
days = (number_of_days - years * 365 - months*30)
print("Years = ", years)
print("Months = ", months)

print("Days = ", days)


4. Write a python program to concatenate two strings using string handling functions

s1=input(“Enter the first string”)

s2=input(“Enter the second string”)

print("".join([str1, str2]))

# join() method is used to combine

# the string with a separator Space(" ")

str3 = " ".join([str1, str2])

print("The new combined string is:",str3)

5. PYTHON program to find the largest and smallest numbers from the given ‘n numbers

lst = []

num = int(input('How many numbers: '))

for n in range(num):

numbers = int(input('Enter number '))

lst.append(numbers)

print("Maximum element in the list is :", max(lst), "\nMinimum element in the list is :",
min(lst))

Python program to find the factorial of a n number provided by the user.

# change the value for a different result

num = 7

#num = int(input("Enter a number: "))

factorial = 1

# check if the number is negative, positive or zero


if num < 0:

print("Sorry, factorial does not exist for negative numbers")

elif num == 0:

print("The factorial of 0 is 1")

else:

for i in range(1,num + 1):

factorial = factorial*i

print("The factorial of",num,"is",factorial)

Write a PYTHON program to print the sum of current number and previous number

print("Printing current and previous number and their sum in a range(10)")

previous_num = 0

# loop from 1 to 10

for i in range(1, 11):

x_sum = previous_num + i

print("Current Number", i, "Previous Number ", previous_num, " Sum: ", previous_num +
i)

# modify previous number

# set it to the current number

previous_num = i

Write a PYTHON program to print characters from a string that are present at
an even index number

You might also like