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

Python Programming Lab Exercises

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

Python Programming Lab Exercises

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

P y t h o n Programming Skills (Lab 1)

Home Work

1. Answer to the following questions:


N Question T/F
1 Python is an open-source license (OSL) language.

2 Python is low-level language.

3 In compiled languages,source code is executed line by line.

4 Interpreted code run slower.

5 Python works only on Windows platforms.

6 In Python, print() is built-in function.

7 Docstrings affects the code execution.

8 Keywords can be used as identifiers

9 -USA is a valid identifier.

10 The input() function may has an optional prompt string.

2. Write a Python program to print the following output

Hello:)
How are you?!!
Welcome to python course in UQU!!!

3. Write a Python program which;


a. Has four variables, varl, var2, var3, and var4.
b. Assign the following values: 120 to varl, and "Umm AI-Qura University" to var2,
c. Input values from keyboard and assign them to var3 and var4.
d. Print the variables.

4. Trace the following source code and find out the outputs:

# print('What is your name?')


print ('What is your name?')
name= input()# read a single line and store it in the variable "name"
print ('Hi'+ name+'!')

a= int(input("input the 1st value :"))


b = int(input("input the 2nd value:"))
s=a+b
print ("The sum=",s)

5. Write a program in Python:


Define three variables: My_age, My_name, and My_tall.
Input your age into My_age. Input
your name into My_name. Input
your tall in em into My_tall.
Print out your name,your age,and your tall respectively.
*Use suitable prompt-messages in input and output functions.
6. Write a program that prompt the user to enter a string. The program should then print the
following:
a) The total number of characters in the string.
b) Printing the string 10 times.
c) The first character of the string.
d) The first three characters of the string.
e) The last three characters of the string. f)
Printing the string backwards.
g) The second character ofthe string ifthe string is long enough.
h) The string with its first and last characters removed.

7. Write a program that generates a random number, x between 1and 50, a random number y between
2 and 5,and computes xv.

8. Write a program that asks the user to enter two numbers, x and y. The program then should convert
x to hexadecimal andy to octal and print the two results.

9. Will the following lines of code print the same thing? Explain why or why not.
x=6 x=7
print(G) print(x)
print("6") print("x")

You might also like