-
Notifications
You must be signed in to change notification settings - Fork 0
/
6.py
77 lines (54 loc) · 2.35 KB
/
6.py
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
#Write a Python code for the following: 1) Ask the user to enter the name of his favorite car. 2) Ask the user to enter a Number.
# Display the name of the user’s favorite car, the number of times specified in the second step.
#Sample Input 1: Toyota 2 Sample Output 1: Toyota Toyota
x = "Veyron"
y = 3
for i in range(y):
print(x)
#Write the Python code of a program that adds all numbers that are multiples of both 7 and 9 up to 600 (including 600) i.e. 63, 126, 189, 252, ....
#The output of your program should be: 2835 (since 63 + 126 + 189 + 252 + 315 + 378 + 441 + 504 + 567 = 2835)
x = 601
p = 0
for i in range(x):
if i % 7 == 0 and i%9 == 0:
p = p + i
print(p)
#Write the Python code of a program that adds all numbers that are multiples of either 7 or 9 up to 600 (including 600) i.e. 7, 9, 14, 18, 21, 27, 28, 35, 36..... .Ensure that numbers like 63, 126, 189 which are multiples of both 7 and 9 are added only once in the sum.
#The output of your program should be: 42649
x = 601
r = 0
for i in range(x):
if i % 7 == 0 or i % 9 == 0:
r = r + i
print(r)
#Write a Python code of a program that adds all numbers that are multiples of either 7 or 9 but not both, up to 600 (including 600) i.e. 7, 9, 14, 18, 21..... and so on but not the numbers 63, 126, 189..... which are multiples of both 7 and 9.
#The output of your program should be: 39814
x = 601
r = 0
for i in range(x):
if i % 7 != 0 and i % 9 == 0:
r = r + i
elif i % 7 == 0 and i % 9 != 0:
r = r + i
print(r)
print('''(*)Write a Python code that will calculate the value of y if the expression of y is as follows
(n is the input): 𝑦=1^2−2^2+3^2−4^2+5^2.........+𝑛^2
Input 1: 5 Output 1: 15. Input 2: 10 Output 2: -55. Input 3: 20 Output 3: -210.''')
val = int(input("Enter your Number: "))
sum = 0
for i in range(val+1):
if i % 2 == 0:
sum -= (i)**2
else:
sum += (i)**2
print(sum)
print('''Write a Python code that will read 5 numbers from the user.
Your program should print the first number, the product of the first 2 numbers, the product of the first 3 numbers,
and so on up to the product of 5 numbers.
Sample Input 1: Sample Output 1:
1 2 3 4 5. 1 3 6 10 15''')
ans = 1
for i in range(5):
inp = int(input("Enter number no " +str(i+1)+ ":"))
ans *= inp
print(ans)