0% found this document useful (0 votes)
9 views

Python Assignment 1 (Q 1-15)

The document contains Python code snippets that demonstrate various operations on lists, strings, and numeric values. Some key operations include: 1. Looping through lists/strings to count, print, or manipulate elements. 2. Accepting user input as lists/strings and performing operations like splitting, reversing, indexing. 3. Checking for occurrences of values, unique values, numeric vs non-numeric values in lists.

Uploaded by

Satya Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Python Assignment 1 (Q 1-15)

The document contains Python code snippets that demonstrate various operations on lists, strings, and numeric values. Some key operations include: 1. Looping through lists/strings to count, print, or manipulate elements. 2. Accepting user input as lists/strings and performing operations like splitting, reversing, indexing. 3. Checking for occurrences of values, unique values, numeric vs non-numeric values in lists.

Uploaded by

Satya Prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

new*

new* new* new* new* new*

1 I #1
2 n=int(input('enter a no.' ))
3 a=O
4 b=l
5 c=O
6 d=l
7 while d<=n:
8 d=d+l
9 print(c,end= 'J)
10 a=b
11 b=c
12 c=a+b

} I < I > I = I -

1 3 5 6 7 9 0
% \ I = [ l < .> { }

q w e r t y u I 0 p
@
f - . k' I # £ & +
a s d g h J
>

0 z
*
X C V b' n m? €)
e I
English
. CD
new*

new* new* new* new* new*


1 #21
2 ch=l
3 p,n,z=0,0,0
4 while type(ch)==int:
5 ch=eva I(i nput('enter no.'))
6 if type(ch) != int:
7 break
8 elif ch<O:
9 n+=l
10 elif ch>O:
11 p+=l
12 elif ch==O:
13 z+=l
14 print('no. of positive no:',p)
15 print('no. of negative no.:',n)
16 print('no. of zeros:',z)
new*
new* new* new* new* new*

3 a='*'
4 for i in range (1,n+1):
5 print(a*i)
Fnf¥VP
Gt£!P new*

1 #4J
2 n=int(input('enter a no.'))
3 for i in range(1,n+1):
4 if i%3!=0:
5 print(i)
6

~ B II # I
t'- f\ -

O\Q pr:x l )

\C
P.A.!3E NO.

--- -----
____________
_,_..___________________ ,
DATE I I

(l
new*

new* new* new* new* new*


1 #61
2 a=input('1 ')
3 k=input('2')
4 x=i nt(i nput('entrr no.'))
5 b=a [:x]+k[len (k)-x:]
6 print(b)

I ~
new*

new* new* new* new* new*


1 #71
2 a=input('enter a string')
3 b=a.split()
4 s=O
5 for i in b:
6 if i[O]=='a' or i[O]=='A' :
7 print(i)
8 s=s+1

I ~
new*
new* new* new* new* new*
1 #8
2 a=input('enter a string')
3 b=a.split()
4 for i in b:
5 if len(i)>=~:
6 print(i)
new*
new* new* new* new* new*
1 #10
2 a=input('enter a string')
3 s= "
4 b=a.split()
5 for i in b:
6 s+=i[::-1]
7 s+= ' ·1
8 print(s)
new*

new* new* new* satya prakash 11125.p

1 #11
2 a=eval(input('enter list' ))
3 b=eval(input('enter element to be
searched'))
4 for i in range(O,len (a)):
if b==a[i]:
prin~ b, 'found at:',i~

I ~
new*
satya prakash 11125.py calculator.sp.py new*

1 #12
2 a=eval(input('enter list' ))
3 b=int(input('enter no. of value to be
deleted'))
4 for i in range(b):
5 c=a.pop()
6 print(c,end= ',i)
7

I ~
new*
new* new* new* new* new*
1 #13
2 a=eval(input('enter list' ))
3 for i in a:
4 b=a .count(i)
5 if b!=l:
6 printK]i,'occur',b,'no. of times')I

# I ( I i I [ I ~
1 3 5 6 7 9 0
% \ I = [ l < .> { }

q w e r t y u I 0 p
@ # £ & .+ (
I>
a s d f- g h J k

&1 z
*
X C V b' n m'm
81 English
I CD
new*

new* new* new* new* new*

1 #14
I

2 a=eval(input('enter list' ))
3 s=O
4 for i in a:
5 b=a .count(i)
6 if b==l:
7 print(i)
8 I s+=l
9 print:{s,'no. of unique value.

# I ( I i I [ I ~
1 3 5 6 7 9 0
% \ I = [ l < .> { }

q w e r t y u I 0 p
@
f - . #
I £ & + (
a s d g h J k >

* ?

0 z X C V b' n m 0

e I
English
. CD
new*
new* new* new* new* new*

1 I #1s
2 a=eval(input('enter list'))
3 s=O
4 for i in a:
5 if type(i)==int or type(i)==float:
6 s=s+1
I

7 k=len(a)-s
8 print("no. of numeric values:",s)
9 print] "no. of non-numeric values:",k~

# I ( I i I [ I • J I

1 3 4 5 6 7 9 0
% \ I = [ l <
• > { }

q w e r t y u I 0 p
@
f - . k' I i
# £ & +
a s d g h J
• ?

0 1z X C V b' n m 0
------

I
English
.
0

You might also like