Monday, April 2, 2012


Python Labsheet 2
1.       Write a program to output a text message. Save the file as “Output.py” (use print command)
2.       Write a program to input some text , sore it in a variable and output that text. Save it as “input_output.py”.{Use raw_input(“Enter some text”) command to input the text}
3.       Write down the difference of output of these between these two lines.
a.       thetext = raw_input("Enter some text ")
b.      thetext = raw_input("Enter some text \n")
4.  Type the following program and save it as “input_output2.py”. Run the program.
prompt  = "Enter  some text "
thetext = raw_input(prompt)
print "This is what you entered:"
print thetext
5.   Type the following a  and b commands in python shell. What is the difference of a and b. State the reason for the difference.
a.  >>> number1= raw_input("Enter the first number: “)
>>> print number1

b. >>>number1= float(raw_input("Enter the first number: “)
>>>print number1
                
6.  >>>number1= float(raw_input("Enter the first number: “)
>>> print “The number you entered is” +number1
You will get an error  when executing the two lines above. Describe why  ? After running the above two command Change the second line to remove the error.

7.       number1 = raw_input("Enter first number:\n") what will be the dada type of number1 ? check your answer ?
8.       Write a python program to calculate the total and average of any user input 3 numbers. The program should display the total and the average like this.
The total is 56.98
The average is 25
9.       Total and count are two variables. Write a program and initialize them to 0. When you run your program the user should enter 3 numbers.  Write  a  program  calculate the total and the average for  user input 3 numbers. The program should do using the while keyword. (while loop).
 The shower smiles in a politician.
10.    Here you get mixing data types in expressions . Mixed type expressions are "converted up"  converted up means to take the data type with the greater storage  float has greater storage (8 bytes) than a regular int (4 bytes) write down the result after execute the code

a.       print 2 + 4
b.      print 2 + 4.0
c.       print 6 - 4.0
d.      print 6 * 3.0
e.      print 6 / 3
f.        print 6 / 3.0
g.       print 6 % 3.0
h.      print 6 // 3.0 # floor division: always truncates fractional remainders
i.         print -5.0
j.        print 3**2
k.       print 3**2.0  
   
11.   these are string objects Write down the result after execute the code.
print "Hello out there"
print 'Hello'
print "Where's the spam?"
print 'x'
12.   Type the following program and write the result. Examine the code and point out the error before you run it.   If there is an error in the code then comment it and run the program again.
a = 'Hello students'
b = "how is programming?"
c = a + b
print c
d = c + 10
d = c + str(10)
print d
13.In this program you will see how type conversion has done.
a = "10"
b = '99'
c = a + b
i)        Write the command to Print the value of c
ii)       Check the data type of c
iii)     How can you convert the data type of c to integer and assign tits  value to c

14.    If x= 6.3 ,how you can round this floating point number and convert to the nearest integer.
15.      Here you get  Boolean expressions which result in a value of  true or false. ( Note that Python stores true as integer 1, and false as integer 0  but outputs 'true' or 'false' from print statements)

print 7 > 10
print 4 < 16
print 4 == 4
print 4 <= 4
print 4 >= 4
print 4 != 4
print 4 <> 4

Check Out This Great Website I Came Across! Hi, I Just Came Across This Wonderful Website

Check out this great website I came across!
Hi, I just came across this wonderful website, paying for form filling work without any Joining Fees or Investment. They pay 30 cent to 50 cent USD per data entry form.
The best part of the company is their referral program where you can start earning instantly from 30 cent to $10.00 USD for each member you refer. You get paid monthly by PayPal or cheque after reaching a payout of $40 USD
One can easily make handsome earnings by little efforts. Just check it out yourself, it is really an amazing opportunity.
Visit.Click here. earnparttimejobs.com/index.php?id=2700075
Happy earnings EarnPartTimeJobs.com is trusted by more than TWO million members as an opportunity to work online. Thanks for reading!

No comments:

Post a Comment

Memory Locatıons and Addresses (Week 3) - ppt download

Memory Locatıons and Addresses (Week 3) - ppt download : Memory Locations and addresses We will first consider how the memory of a computer...

Total Pageviews

Followers