Professional Documents
Culture Documents
SIMPLE PROGRAMS
1) Add natural numbers up to n where n is taken as an input from user
using recursive function Print the sum
PROGRAMS USING FUNCTIONS
1) Prompt the user to enter the password, where a user can enter a
wrong password only 3 times. If the entry is correct display “Login
Successful
Test 1 2 3
Case
Input My name is Kumaraguru College Problem based
python of Technology on Strings
Outp python is Technology of Strings on
ut name My College Kumaraguru based Problem
2) Write a program that accepts a sequence of words that are hyphen separated as
input and prints the words in a hyphen-separated sequence after sorting them
alphabetically.
Test 1 2 3
case
Input green-red-yellow-black- red-yellow- green-yellow-
white black white
Outpu black-green-red-white- black -red- green-white-
t yellow yellow yellow
3) Write a program that accepts a sentence as input and calculates the
number of letters, digits and special characters.
Test Case 1 2
Input sentence hello world! There is a laptop with
@$ 123 #CS123…
Outp Letters 10 20
ut Digits 3 3
Special 3 4
Characters
8) Write a program that takes an IP address of the form P.Q.R.S as input, where
P, Q, R and S are decimal numbers in the range 0 to 255, and prints the class
of the address as indicated in the table below.
Value of P Class
1 – 126 A
128 – 191 B
192 – 223 C
224 – 239 D
240 – 254 E
Test 1 2 3 4 5
Case
Input 224.220.206 126.220.206 127.0.0 0.100.100.1 255.255.255.
.91 .91 .1 00 255
Outp Class D Class A Invali Invalid Invalid
ut d