Beruflich Dokumente
Kultur Dokumente
Lalda
SE A
Roll No-53
Assignment No-1
Code:
oc=0o123
bin=0b0101
hex=0xFC1
print("Octal value 123 in Decimal is ",int(oc))
print("Binary value 0101 in Decimal is ",int(bin))
print("Hexadecimal value FC1 in Decimal is ",int(hex))
Output:
Octal value 123 in Decimal is 83
Binary value 0101 in Decimal is 5
Hexadecimal value FC1 in Decimal is 4033
Code:
b=input("Enter an Binary value ")
o=input("Enter an Octal value ")
h=input("Enter an Hexadecimal value ")
print("Binary value ",b," in decimal is",int(b,2))
print("Octal value ",o," in Decimal is",int(o,8))
print("Hexadecimal value ",h," in decimal is",int(h,16))
Output
Enter an Binary value 0101
Enter an Octal value 123
Enter an Hexadecimal value fc1
Binary value 0101 in decimal is 5
Octal value 123 in Decimal is 83
Hexadecimal value fc1 in decimal is 4033
Code:
Output:
Average is 2.0
4) A python program to accept a group of strings separated
by commas and display them again.
Code-
Output-
Code:
Output:
Enter a list 1 2 3 4
Code:
Output:
Code-
Output-
Enter a number 8
Number is even
Enter a number 7
Number is odd
Code:
Output-
Enter a number 1 2 3 4 5
One
Two
Three
Four
Five
OR
Code:
d={1:"One",2:"Two",3:"Three",4:"Four",5:"Five"}
key=int(input("Enter any number in between 1-5 (both inclusive)"))
if key<1 or key>5:
print("Invalid Enter Positive Number")
else:
print(key," in words is ",d[key])
Output
Enter any number in between 1-5 (both inclusive) 3
3 in words Three
8) A python program to display each character from a string
using sequence index.
code-
Output-
p r a t i k s h a
Code:
l=len(x)
i=0
sum=0
while i<l:
sum+=x[i]
i+=1
Output:
Enter a list:1 2 3
10.b) A Python program to assert if a user enters a number greater than zero.
Code:
x=int(input(“Enter a number:”))
assert x>0,”Only positive number allowed”
print(“You Entered :”,x)
Output:
Enter a number:2
You Entered : 2
Enter a number:-9
Traceback (most recent call last):
File "C:/Users/prati/PycharmProjects/Hello/app.py", line 2, in <module>
assert x>0,"only positive number allowed"
AssertionError: only positive number allowed
11) A Python program to test whether a number is even or odd using functions.
Code:
def check(x):
if x%2==0:
print(x," is an even number")
else:
print(x," is an odd number")
13) A Python program to multiply all the numbers in a list using functions.
Code:
def multipy(x):
prod=1
for i in x:
prod*=i
return prod
lst=[int(x) for x in input("Enter list elements").split()]
print(“Product of all numberin list is: ”,multipy(lst))
Output:
enter a list: 1 4 3
Product of all number in list is: 12
def sub(*s):
su=2
for i in s:
su-=i
return su
a=add(1,2,3,4,5)
print("sum of 1 2 3 4 5 is:",a)
subs=sub(1,2,3,4,5)
print("subraction of 1 2 3 4 5 is:",subs)
m=mul(1,2,3,4,5)
print("product of 1 2 3 4 5 is : ",m)
Output
sum of 1 2 3 4 5 is : 15
subraction of 1 2 3 4 5 is: -13
product of 1 2 3 4 5 is : 120