0% found this document useful (0 votes)
15 views7 pages

Assignment Python

The document contains code snippets that demonstrate various Python programming concepts including: - Using conditionals like if/else statements to check for even/odd numbers, divisibility, and age eligibility - Using a for loop with a continue statement - Calculating factorials with a for loop - String operations like concatenation, multiplication, indexing, slicing, and length - Common list methods like append, extend, remove, reverse, sort, and built-in functions like len, max, min - Basic tuple usage and indexing

Uploaded by

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

Assignment Python

The document contains code snippets that demonstrate various Python programming concepts including: - Using conditionals like if/else statements to check for even/odd numbers, divisibility, and age eligibility - Using a for loop with a continue statement - Calculating factorials with a for loop - String operations like concatenation, multiplication, indexing, slicing, and length - Common list methods like append, extend, remove, reverse, sort, and built-in functions like len, max, min - Basic tuple usage and indexing

Uploaded by

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

# -*- coding: utf-8 -*-

"""

@author: GSB
"""

a=int(input("Enter any Number to test whether it is odd or even:"))


if a%2==0:
print ("The number is even")
else:
print ("The number is odd")

a=int (input ("Enter any Number"))


if a%5==0:
print("Hello")
else:
print("Bye")

a=int(input("Enter a year"))
if a%4==0:
print("It is a leap year")
else:
print("it is not a leap year")

a=int(input("Enter age"))
if a>=18:
print("Eligible for voting")
else:
print("Not eligible for voting")

for num in range(6):


num=num + 1
if num ==3:
continue
print(" Num has value" +str(num))
print('end of loop')

a=int(input("Enter age"))
if a%4==0:
print("Eligible for voting")
else:
print("Not eligible for voting")

num=int(input("what is your number:"))


factorial= 1
if num < 0:
print("sorry,factorial is 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)

# -*- coding: utf-8 -*-


"""

@author: GSB
"""

"hello" + "world"

"hello"*3

"hello"[0]

"hello"[-4:-1]

len("hello")

Str='Python class'
Str.upper()

Str='Python class'
Str.count('s')

Str='Python class'
Str.swapcase()

li=["abc", 42, 4.55, 233]


li[-1]

li=["abc", 42, 4.55, 233]


li.reverse()
li

li=[5,2,6,8]
li.sort()
li

s=[1,2,3]
t=['begin',s,'end']
t
t[1][1]

len(s)
max(s)
min(s)

list(s)

li = 'abcdefghijklmno'
li.count('f')

k = ['abc','def','ghijklmno']
k.append('def')
k

fruits=['apple','banana','cherry']
cars=['ford','bmw']
fruits.extend(cars)
cars

fruits=['apple','banana','cherry']
fruits.remove('apple')
fruits

tu=(23,45,'abc')
tu[1]

You might also like