0% found this document useful (0 votes)
61 views2 pages

IO Operations

This document provides code snippets and explanations for 5 programs involving user input and output operations: 1. A program to print the absolute value of a number input by the user. 2. A program to determine the type of input provided by the user. 3. A program to take user input, cube it using a lambda function, and print the output. 4. A program to check if a number input by the user is a prime number. 5. A program that prints multiple values separated by dashes on the same line.

Uploaded by

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

IO Operations

This document provides code snippets and explanations for 5 programs involving user input and output operations: 1. A program to print the absolute value of a number input by the user. 2. A program to determine the type of input provided by the user. 3. A program to take user input, cube it using a lambda function, and print the output. 4. A program to check if a number input by the user is a prime number. 5. A program that prints multiple values separated by dashes on the same line.

Uploaded by

Ramiz Mehran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 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)

You might also like