Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0154a4d

Browse files
More Programs are added and some of them modified.
1 parent 1c98bf4 commit 0154a4d

15 files changed

+170
-0
lines changed

β€Ž11. Program.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Write a program to accept total sales amount and find the profit amount @ 5%.
33
4+
Description:
5+
46
lets say total sales is 50k so we have to find profit which is 5% of the total sales.
57
if a person sales 50k a day then it means 5 percent of profit is 50,000 * 5/100 = 25,00.
68
so 25,00 is the profit he gains if he sales 50,000 a day.

β€Ž14. Write a program to find the middle number in a group of three numbers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
no3 = int(input('Enter 3rd number: ')) # 6
44

55
"""
6+
Description:
7+
68
The logic in this question is that if we have 3 numbers like a,b and c so in this case if we say a is a
79
middle number then there is a two conditions. first is that a is greater than b and less than c.
810
the second condition is that a is less than b and greater than c. and in this case both conditions works
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
i = 1
2+
while i <= 10:
3+
print(i)
4+
i += 1
5+
else:
6+
print('The loop stops when i is equal to 11.')
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# n = int(input('Enter Number upto which you want to print: '))
2+
# i = 1
3+
# if n > 0:
4+
# while i <= n:
5+
# print(i)
6+
# i+=1
7+
# # the final value of i is 6 but it will not print because the condition becomes false when i = 6.
8+
# else:
9+
# print('You entered negative number that\'s why program does\'nt print numbers')
10+
11+
12+
13+
"""
14+
This is the second logic of the same problem problem which we solved above.
15+
"""
16+
17+
i = int(input('Enter the initization number: '))
18+
n = int(input('Enter Number upto which you want to print: '))
19+
if n > 0:
20+
while i <= n:
21+
print(i, end=" ")
22+
i+=1
23+
# the final value of i is 6 but it will not print because the condition becomes false when i = 6.
24+
else:
25+
print('You entered negative number that\'s why program does\'nt print numbers')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
i = 10
2+
while i >= 1:
3+
print(i)
4+
i -= 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# n = int(input('Enter initialization number: '))
2+
# while n >= 1:
3+
# print(n)
4+
# n -= 1
5+
6+
n = int(input('Enter initialization number: '))
7+
i = int(input('Enter a number down till which you want to print: '))
8+
while n >= i:
9+
print(n, end=" ")
10+
n -= 1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Description:
3+
4+
lets say if a user enters 5 for the value of n so it means the program calculates the sum of numbers from
5+
1 till 5.
6+
like 1 +γŸγ™ 2 +γŸγ™ 3 +γŸγ™ 4 +γŸγ™ 5 =わ 15. so the sum of the numbers from 1 till 5 is equal to 15.
7+
"""
8+
9+
n = int(input('Enter Number upto which you want to sum: '))
10+
i = 1
11+
sum = 0 # Here we set sum = 0 because zero is the number that does'nt effect the sum of two numbers like
12+
# if we add 1 + 0 then answer is 1 so it means 0 does'nt effect the sum.
13+
while i <= n:
14+
sum += i
15+
i += 1
16+
print('The sum =', sum)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = int(input('Enter a number upto which you want to sum: '))
2+
i = 1
3+
sum = 0
4+
while i <= n:
5+
sum += i**2 # or you can write sum += i*i
6+
i += 1
7+
print('The sum of squares =', sum)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
n = int(input('Enter a number upto which you want to sum: '))
2+
sum = 0
3+
i = 1
4+
while i <= n:
5+
sum += i**3
6+
i += 1
7+
print("The sum of cubes =", sum)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
Short Description:
3+
4+
If user enters 10 for the value of n than only even numbers between 1 to 10 should be printed.
5+
"""
6+
7+
# 1st method:
8+
# n = int(input('Enter Number upto which you want to print: '))
9+
# i = 2 # initialize the loop with i = 2 because we want to print only even numbers.
10+
# while i <= n: # because we want to print 10 also if n = 10 so thats why = is with < sign.
11+
# print(i)
12+
# i += 2
13+
14+
# 2nd Method:
15+
n = int(input('Enter Number upto which you want to print: '))
16+
i = 1
17+
while i <= n:
18+
if i % 2 == 0:
19+
print(i)
20+
i += 1 # this increament is independent of the if block means this increament executes every time.
21+

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /