Sunteți pe pagina 1din 2

Chapter 3:

HOW USER INTERACT WITH THE APPLICATION? - I/O OPERATIONS


1. Write a program to print absolute value of a given number.
2. Write a program to find the type of the given input.
3. Write a program to to take input and convert it into cube at input() function only and print
the output.
4. Write a program to check whether given input is a prime number.
5. Write a program that prints output in the same line each value seperated by -.
like 1-4-5-g-6-8.0 e.t.c.,
Answers:
1.
#!/usr/bin/python
x=float(input('enter input'))
if x>=0:
print ("absolute value of", x ,"is",x)
else:
print ("absolute value of", x, "is",-x)
2.
#!/usr/bin/python
x=input('Enter input':)
print (type(x))
if type(x)==type(""):
print ("It is a string")
elif type(x)==type(1):
print ("It is an integer")
elif type(x)==type(1.0):
print ("It is a floating point")
else:
print ("It is other than integer,floating point and string")
3.
#!/usr/bin/python
x=(lambda x:x*x*x)(input('enter'))
print x
4.
#!/usr/bin/python
num = int(input("Enter a number: "))
if num > 1:
for i in range(2,num):
if (num % i) == 0:
s='False'
break
else:

s='True'
else:
print(num,"is not a positive number")
if s=='False':
print(num,"is not a prime number")
else:
print(num,"is a prime number")
5.
#!/usr/bin/python
li=[1,4,5,'g',6,8.0]
i=0
for k in li:
if i!=(len(li)-1):
print (k,end="-")
i+=1
else:
print (k)

S-ar putea să vă placă și