1-10 Programmsmanual
1-10 Programmsmanual
Write a program that asks the user for a weight in kilograms and converts it to
pounds. There are 2.2 pounds in a kilogram.
Aim: To Write a python program that asks the user for a weight in kilograms and converts it to pounds. There
Source code:
a=a*2.2
print("weight=",a)
OUTPUT:
weight= 220.00000000000003
Exercise 2:
Write a program that asks the user to enter three numbers (use three separate input
statements). Create variables called total and average that hold the sum and average of
the three numbers and print out the values of total and average.
Aim: To Write a python program that asks the user to enter three numbers. Create variables called total and
average that hold the sum and average of the three numbers and print out the values of total and average.
Source code:
a=int(input("enter a value="))
b=int(input("enter b value="))
c=int(input("enter c value="))
total=a+b+c
average=(a+b+c)/3
OUTPUT:
enter a value=10
enter b value=20
enter c value=30
Source code:
for i in range(8,90,3):
print(i)
OUTPUT:
8
11
14
17
20
23
26
29
32
35
38
41
44
47
50
53
56
59
62
65
68
71
74
77
80
83
86
89
Exercise 4:
Write a program that asks the user for their name and how many times to print it. The
program should print out the user’s name the specified number of times.
Aim: To Write a python program that asks the user for their name and how many times to print it. The program
should print out the user’s name the specified number of times.
Source code:
a=input("enter a string=")
while n>=0:
n=n-1
print(a)
OUTPUT:
enter a string=Rajesh
enter the range of the string=3
Rajesh
Rajesh
Rajesh
Exercise 5:
Use a for loop to print a triangle like the one below. Allow the user to specify how
high the triangle should be.
*
**
***
****
Aim: To Write a python program that asks the Use a for loop to print a triangle
Source code:
for i in range(0,4):
for j in range(0,i+1):
print("*",end="")
print("\r")
OUTPUT:
**
***
****
Exercise 6:
Generate a random number between 1 and 10. Ask the user to guess the number and
print a message based on whether they get it right or no
Aim: To Write a python program that asks the user to Generate a random number between 1 and 10. Ask the user
to guess the number and print a message based on whether they get it right or no
Source code:
import random
y=int(input("guess a number"))
a=1
b=10
sum=random.randint(a,b)
if y==sum:
else:
OUTPUT:
guess a number 9
the output number= 10
oops! better luck next time
Exercise 7:
Write a program that asks the user for two numbers and prints Close if the numbers
are within .001 of each other and Not close otherwise.
Aim: To Write a python program that asks the user for two numbers and prints Close if the numbers
are within .001 of each other and Not close otherwise.
Source code:
if a<.001<b:
else:
OUTPUT:
Write a program that asks the user to enter a word and prints out whether that word
contains any vowels.
Aim: To Write a python program that asks the user to enter a word and prints out whether that
Source code:
a=input("enter a word=")
vowels=['a','e','i','o','u']
for i in vowels:
if i in a:
print(i)
OUTPUT:
Write a program that asks the user to enter two strings of the same length. The
program should then check to see if the strings are of the same length. If they are not,
the program should print an appropriate message and exit. If they are of the same
length, the program should alternate the characters of the two strings. For example, if
the user enters abcde and ABCDE the program should print out AaBbCcDdEe.
Aim: To Write a python program that asks the user to enter two strings of the same length.
Source code:
OUTPUT:
Write a program that asks the user for a large integer and inserts commas into it
according to the standard American convention for commas in large numbers. For
instance, if the user enters 1000000, the output should be 1,000,000.
Aim: To Write a python program that asks the user for a large integer and inserts commas into it
according to the standard American convention for commas in large numbers.
Source code:
s=1000000
print("{:,}".format(s))
OUTPUT:
1,000,000