Questions
1. a=4
b='string'
print a+b
what is the error in the above program? Please correct the error.
Find out the output and its type of the following statements.
int(5.0)
float(5)
str(7)
int("")
str(7.0)
float("5.0")
int("five")
Write a program to check a character in a string.
Note: Take a string of your wish.
Consider you have 22 apples,20 bananas,30 carrots. Create variables for each fruit and print the output as follows,
I have 22 apples 20 bananas 30 carrots.
Note:In place of number use the variable.
Answer the following questions.
Which function used for the address of a variable?
Which function used to know whether a given variable is keyword?
Which function used to convert object into an expression string?
Which function used to find maximum size that integer can take?
Answers:
1.
cannot concatenate string with integer.
print str(a)+b
2.
Ans :
5 integer
5.0 floating point
7 string
error (invalid literal for int)
7.0 string
5.0 float
error
3.
#!/usr/bin/python
x="python"
ch='t'
print ch in x
Note: Output will be 'True' if character found otherwise 'False'
4.
#!/usr/bin/python
apple=22
banana=20
carrot=30
print "I have "+str(apple)+" apples "+str(banana)+" bananas "+str(carrot)+" carrots."
5.
id(variablename)
keyword.iskeyword(name)
repr(word)
sys.maxint
Operators supported for data manipulation and comparison
Consider a=4,b=6,c=10.Now write a program to have all the arithmetic operations(+,-,*,/,%,**,//) between them. For ex:a+b+c and also find the output.
Consider a=27,b=63.Now write a program that has all bitwise operations and also find the output.
Consider a=7,b=5. Now,check whether a is greater than b if so increment it by 1.
Consider a=5 What is the output of the following a<<3,a>>3,a>>2 and a<<2.
A man has taken a debt of 200 R.S. Write a program to find simple interest after 2 years with rate of interest=3% and what is the Interest?
Answers:
1 Ans.
Operator Output
+ 20
- -12
* 240
/ 0
% 4
** Infinity
// 0
2 Ans.
Operator Output
& 27
| 63
^ 36
~a -28
a<<2 108
a>>2 6
3 Ans.
#!/usr/bin/python
a=7
b=5
if a>b:
print "a is greater than b and the value of a becomes",a+1
elif a==b:
print "a is equal to b"
else:
print "a is smaller than b"
4 Ans.
0
40
1
20
5.
#!/usr/bin/python
p=200
t=2
r=3
si=p*t*r/100
print si
The interest is 12 R.S.
1. a=4
b='string'
print a+b
what is the error in the above program? Please correct the error.
Find out the output and its type of the following statements.
int(5.0)
float(5)
str(7)
int("")
str(7.0)
float("5.0")
int("five")
Write a program to check a character in a string.
Note: Take a string of your wish.
Consider you have 22 apples,20 bananas,30 carrots. Create variables for each fruit and print the output as follows,
I have 22 apples 20 bananas 30 carrots.
Note:In place of number use the variable.
Answer the following questions.
Which function used for the address of a variable?
Which function used to know whether a given variable is keyword?
Which function used to convert object into an expression string?
Which function used to find maximum size that integer can take?
Answers:
1.
cannot concatenate string with integer.
print str(a)+b
2.
Ans :
5 integer
5.0 floating point
7 string
error (invalid literal for int)
7.0 string
5.0 float
error
3.
#!/usr/bin/python
x="python"
ch='t'
print ch in x
Note: Output will be 'True' if character found otherwise 'False'
4.
#!/usr/bin/python
apple=22
banana=20
carrot=30
print "I have "+str(apple)+" apples "+str(banana)+" bananas "+str(carrot)+" carrots."
5.
id(variablename)
keyword.iskeyword(name)
repr(word)
sys.maxint
Operators supported for data manipulation and comparison
Consider a=4,b=6,c=10.Now write a program to have all the arithmetic operations(+,-,*,/,%,**,//) between them. For ex:a+b+c and also find the output.
Consider a=27,b=63.Now write a program that has all bitwise operations and also find the output.
Consider a=7,b=5. Now,check whether a is greater than b if so increment it by 1.
Consider a=5 What is the output of the following a<<3,a>>3,a>>2 and a<<2.
A man has taken a debt of 200 R.S. Write a program to find simple interest after 2 years with rate of interest=3% and what is the Interest?
Answers:
1 Ans.
Operator Output
+ 20
- -12
* 240
/ 0
% 4
** Infinity
// 0
2 Ans.
Operator Output
& 27
| 63
^ 36
~a -28
a<<2 108
a>>2 6
3 Ans.
#!/usr/bin/python
a=7
b=5
if a>b:
print "a is greater than b and the value of a becomes",a+1
elif a==b:
print "a is equal to b"
else:
print "a is smaller than b"
4 Ans.
0
40
1
20
5.
#!/usr/bin/python
p=200
t=2
r=3
si=p*t*r/100
print si
The interest is 12 R.S.
No comments:
Post a Comment