0% found this document useful (0 votes)
4 views3 pages

Python Programming Output Examples

The document contains a series of Python programming tasks and their corresponding answers. It includes examples of printing odd numbers, reversing a range of numbers, iterating over strings, summing values, and using nested loops. Additionally, it discusses incrementing variables and printing strings in vertical order.

Uploaded by

Vidhya hs
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)
4 views3 pages

Python Programming Output Examples

The document contains a series of Python programming tasks and their corresponding answers. It includes examples of printing odd numbers, reversing a range of numbers, iterating over strings, summing values, and using nested loops. Additionally, it discusses incrementing variables and printing strings in vertical order.

Uploaded by

Vidhya hs
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

1.

Write a python program to print list of odd number in a vertical order


Answer:
list=[1,2,3,4,5,6,7,8,9,10]
for num in list:
if num % 2 !=0:
print(num, sep="/n ")

[Link] a python program to print number from 0 to 15 in a reverse order.


Answer:
for num in range(15,0,-1):
print(num,sep='/n')

[Link] input is name = ‘Sam Anderson’, What will be the output of the below code:
for e in name:
print(name)
o/p:
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson
Sam Anderson

4. if input is salary = ‘356428’, What will be the output of the below code:
for s in salary:
print(s)
o/p:
3
5
6
4
2
8

5. Find the Output For the Following


numbers = "12345"
sum = "6"
for val in numbers:
sum = sum+val
print("The sum is", sum)
o/p:
612345

6. Find the Output For the Following


sum = 0
for val in range(1, 6):
sum = sum + val
print(sum)
o/p:
15

7. Find the Output For the Following


for num1 in range(3):
for num2 in range(10, 14):
print(num1, ",", num2)
o/p:
0 , 10
0 , 11
0 , 12
0 , 13
1 , 10
1 , 11
1 , 12
1 , 13
2 , 10
2 , 11
2 , 12
2 , 13

[Link] a FOR loop condition to print the following output:


OUTPUT:
India
India
India
Code:
country='india'
for num in range(3):
print(country)

9. Which of the following are the correct ways to increment the value of variable a by 1?
A. ++a++;
B. a += 1;
C. a ++ 1;
D. a = a +1;
E. a = +1;
Answer:B.a+=1

10. Print the given string in Vertical Order.


str = 'Hello Students'
o/p:
str = 'Hello Students'
for val in str:
print(val,sep='/n')

You might also like