Jatin Yadav (CS)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

COMPUTER

SCIENCE

NAME: Itiksha

CLASS:11th - A

ROLL NO:1171

SCHOOL NAME:Flora Dale School]

Due Date:[Type the due date]


INDEX

1. WAP to input welcome message and display it.

2. WAP to input 2 numbers and display the larger/smaller number

3. WAP to input 2 numbers and display the larger/smaller number

4. WAP to generate patterns using nested loop.

5. WAP to show the use of string functions and operations on String.

6. WAP to input strings from the user and display the following details

(i). No. of Capital letters

(ii). No. of Lowercase

(iii). No. of Digits

(iv). No. of Alphabets

7. WAP to input any list from the user and perfom operations and functions
on a list.

8. WAP to input any tuple from the user and perfom operations and functions
on it.

9. WAP to input any tuple from the user and insert value 100 at index 2.

10. WAP to traverse a dictionary inputted by the user.

11. WAP to perform all the operations and functions of a Dictionary.


Question 1:-

WAP to input welcome message and display it.

Answer:-

Input:-

Name=input("Enter your name")

print("Welcome",Name)

Output:-

Question 2:-

WAP to input 2 numbers and display the larger/smaller number.

Answer:-

Input:-

a=int(input("Enter a number"))

b=int(input("Enter a number"))

if a>b:

print(a,"is larger number")

print(b,"is smaller number")

else:

print(b,"is larger number")

print(a,"is smaller number")

Output
Question 3:-

WAP to input 2 numbers and display the larger/smaller number

Answer:-

Input:-

a=int(input("Enter a number"))

b=int(input("Enter a number"))

c=int(input("Enter a number"))

L=[a,b,c]

print(max(L),"is largest number")

print(min(L),"is smallest number")

Output:-

Question 4:-

WAP to generate patterns using nested loop.


Answer:-

Input:-

n=int(input("Enter a number"))

for i in range(0,n):

for j in range(0,i+1):

print("* ",end=" ")

print()

Output:-

Question 5:-

WAP to show the use of string functions and operations on String.

Answer:-

Input:-

String1=input("Enter String")

String2=input("Enter String")
String3=input("Enter String")

#Concatination

print(String1+String2)

#Replication

print(String1*2)

#Membership Operator

Alpha1=input("Enter String")

Alpha2=input("Enter String")

Alpha3=input("Enter String")

print(Alpha1 in String1)

print(Alpha2 in String1)

print(Alpha1 not in String1)

print(Alpha2 not in String1)

#Comparison Operator

print(String1==String2)

print(String1==String3)

print(String1!=String2)

print(String1!=String3)

#Built-in functions

#len()

print(len(String1))

#count()

print(String1.count(Alpha1))

#capitalize()

print(String1.capitalize())
#find()

print(String1.find(Alpha3))

#index()

print(String1.index(Alpha3))

#isalpha()

String4=input("Enter String")

print(String4.isalpha())

#isalnum()

String5=input("Enter String")

print(String5.isalnum())

#isupper()

String6=input("Enter String")

print(String6.isupper())

#islower()

String7=input("Enter String")

print(String7.islower())

#isdigit()

String8=input("Enter String")

print(String8.isdigit())

#isspace()

String9=input("Enter String")

print(String9.isspace())

#istitle()

print(String2.istitle())

#lower()
print(String1.lower())

#upper()

print(String1.upper())

#title()

print(String1.title())

#swapcase()

print(String2.swapcase())

#srtip()

print(String2.strip())

#lsrtip()

print(String2.lstrip())

#rsrtip()

print(String2.rstrip())

Output:-
Question 6:-

WAP to input strings from the user and display the following details

(i). No. of Capital letters

(ii). No. of Lowercase

(iii). No. of Digits

(iv). No. of Alphabets

Answer:-

Input:-

String=input("Enter a string")

u=l=d=a=0

for x in String:

if x.isupper():

u+=1

elif x.islower():

l+=1

elif x.isdigit():

d+=1
elif x.isalpha():

a+=1

print('No. of Capital letters',u)

print('No. of Lowercase',l)

print('No. of Digits',d)

print('No. of Alphabets',a)

Output:-

Question 7:-

WAP to input any list from the user and perfom operations and functions on a list.

Answer:-

Input:-

List1=eval(input("Enter List"))

List2=eval(input("Enter List"))

#Concatination

print(List1+List2)

#Replication

print(List1*2)

#Membership Operator
Element1=int(input("Enter List Elements"))

Element2=int(input("Enter List Elements"))

print(Element1 in List1)

print(Element2 in List1)

#Traversion

for x in List1:

print(x,end=' ')

#Built-in functions

#len()

print(len(List1))

#count()

print(List1.count(Element1))

#index()

print(List1.index(Element1))

#list

T=(1,3,5,7,9)

List3=list(T)

print(List3)

#append

print(List1.append(Element2))

#extend

print(List1.extend(List2))

#pop

print(List1.pop(2))

#reverse
print(List1.reverse())

#sort

print(List1.sort())

#sorted

print(sorted(List1))

#min

print(min(List1))

#max

print(max(List1))

#sum

print(sum(List1))

Output:-
Question 8:-

WAP to input any tuple from the user and perfom operations and functions on it.

Answer:-

Input:-

Tuple1=eval(input("Enter Tuple"))

Tuple2=eval(input("Enter Tuple"))

#Concatination

print(Tuple1+Tuple2)

#Replication

print(Tuple1*2)

#Membership Operator

Element1=int(input("Enter Tuple Elements"))

Element2=int(input("Enter Tuple Elements"))

print(Element1 in Tuple1)

print(Element2 in Tuple1)

#Built-in functions

#len()

print(len(Tuple1))

#count()

print(Tuple1.count(Element1))

#index()

print(Tuple1.index(Element1))

#Tuple

T=(1,3,5,7,9)

Tuple3=tuple(T)
print(Tuple3)

#sorted

print(sorted(Tuple1))

#min

print(min(Tuple1))

#max

print(max(Tuple1))

#sum

print(sum(Tuple1))

Output:-

Question 9:-

WAP to input any tuple from the user and insert value 100 at index 2.

Answer:-

Input:-

Tuple1=eval(input("Enter Tuple"))
List=list(Tuple1)

List[2]=100

Tuple2=tuple(List)

print(Tuple1)

print(Tuple2)

Output:-

Question 10:-

WAP to traverse a dictionary inputted by the user.

Answer:-

Input:-

Dictionary=eval(input("Enter Dictionary"))

for x in Dictionary:

print(x," ",Dictionary[x])

Output:-
Question 11:-

WAP to perform all the operations and functions of a Dictionary.

Answer:-

Input:-

Dictionary1=eval(input("Enter Dictionary"))

Dictionary2=eval(input("Enter Dictionary"))

#Membership Operator

Element1=int(input("Enter Dictionary Elements"))

Element2=int(input("Enter Dictionary Elements"))

print(Element1 in Dictionary1)

print(Element2 not in Dictionary1)

#Traversion

for x in Dictionary1:

print(x," ",Dictionary1[x])

#Built-in functions

#len()

print(len(Dictionary1))

#dict()

Dictionary3=dict()

print(Dictionary3)

#keys()

print(Dictionary1.keys())

#values()

print(Dictionary1.values())

#items()
print(Dictionary1.items())

#get()

Keys=int(input("Enter Key"))

print(Dictionary1.get(Keys))

#update

Dictionary1.update(Dictionary2)

print(Dictionary1)

#del()

del Dictionary1[Element1]

print(Dictionary1)

#clear()

Dictionary1.clear()

print(Dictionary1)

#sorted()

print(sorted(Dictionary1))

#max()

print(max(Dictionary2))

#min()

print(min(Dictionary2))

#sum()

print(sum(Dictionary2))

#popitem()

Dictionary2.popitem()

print(Dictionary2)

#copy()
Dictionary3=Dictionary2.copy()

Dictionary3[Element1]=580

print(Dictionary2)

#fromkeys()

Element3=('key1', 'key2', 'key3')

Element4=0

Dictionary3= dict.fromkeys(Element3,Element4)

print(Dictionary3)

Output:-

You might also like