Python Exercises v1
Python Exercises v1
(part 1)
Question no.1. Write a program in Python which asks you to input any number of hours
& converts it into seconds?
SOLUTION:
Question no.2. Write a program in Python which asks you to input two numbers &
returns the sum of them?
SOLUTION:
Question no.3. Write a program in Python that asks you to enter two numbers, compares
them & tells you which of them is bigger or both are equal?
Python
SOLUTION:
Exercises 1
Networkwalks Academy
SOLUTION:
Question no.5. Write a program in Python that asks you to enter a text string & tells you
its length?
SOLUTION:
1 www.networkwalks.com [email protected]
Question no.6. Write a program in Python that will produce following output using For
loop:
SOLUTION:
2 www.networkwalks.com [email protected]
Question no.7. Write a program in Python that will produce following output using
While loop:
SOLUTION:
Question no.8. Write a program in Python which asks you to input two numbers &
returns the average of them?
SOLUTION:
3 www.networkwalks.com [email protected]
Question no.9. Write a program in Python that will produce following output:
SOLUTION:
var1 = 1
var2 = 2
var3 = "3"
print(var1 + var2 + var3)
SOLUTION:
4 www.networkwalks.com [email protected]
Question no.11. What will be the output of following Python code?
var1 = 1
var2 = 2
var3 = "3"
print(var1, var2, var3)
SOLUTION:
a = 3 + 2 * 4 + 4
print(a)
SOLUTION:
x = 8 + 8 * 9
print(x)
SOLUTION:
5 www.networkwalks.com [email protected]
Question no.14. What will be the output of following Python code?
i = 8 + 8 * 9 + 9 (10-9)
print(i)
SOLUTION:
Question no.15. What will be the output of the following Python code?
p, q, r = 10, 20 ,30
print(p, q, r)
SOLUTION:
Question no.16. Write a program in Python, using For loop, that asks you to enter a
text string & then prints its letters separately?
SOLUTION:
6 www.networkwalks.com [email protected]
Question no.17. Write a program in Python that will produce following output
using only one Print function command (do not use print function more than once, do no use
loop or other functions):
*
* *
* *
* *
*** ***
* *
* *
*****
SOLUTION:
7 www.networkwalks.com [email protected]
Question no.18. Write a program in Python that will produce following output
using 8x Print function commands (use print function eight times, do no use loop or other
functions):
*
* *
* *
* *
*** ***
* *
* *
*****
SOLUTION:
Question no.19. Write a program in Python that will produce following output
using for Loop:
*
* *
* * *
Hint: Use nested for loop (for loop inside another for loop)
SOLUTION:
8 www.networkwalks.com [email protected]
Question no.20. Write a program in Python that will produce following output
using for Loop:
*
* *
* * *
* * * *
* * * * *
Hint: Use nested for loop (for loop inside another for loop)
SOLUTION:
9 www.networkwalks.com [email protected]