-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.py
More file actions
64 lines (54 loc) · 1.45 KB
/
Copy pathnumber.py
File metadata and controls
64 lines (54 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'''
Given two integers A and B. Print all numbers from A to B inclusively, in ascending order, if A < B, or in descending order, if A ≥ B.
'''
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
if a<b:
for i in range(a,b+1):
print(i)
else:
for i in range(a,b-1,-1):
print(i)
'''
10 numbers are given in the input. Read them and print their sum. Use as few variables as you can.
'''
sum=0
for i in range(10):
ai = int(input("Enter the number: "))
sum+=ai
print(sum)
'''
For the given integer N calculate the following sum:
1^3+2^3+…+N^3
'''
sum=0
n=int(input("Enter the number: "))
for i in range(1,n+1):
c=i**3
sum+=c
print(sum)
'''
Given an integer n
, print the sum 1!+2!+3!+...+n!
.
This problem has a solution with only one loop, so try to discover it. And don't use the math library :)
'''
n = int(input("Enter the limit: "))
sum=0
for i in range(1,n+1):
fact=1
for j in range(1,i+1):
fact=fact*j
sum+=fact
print(sum)
'''
Given N numbers: the first number in the input is N, after that N integers are given. Count the number of zeros among the given integers and print it.
You need to count the number of numbers that are equal to zero, not the number of zero digits.
'''
n = int(input("Enter the limit: "))
c=0
for i in range(n):
a=int(input("Enter the number: "))
if a==0:
c+=1
print(c)