Skip to content

Commit 96c1fb2

Browse files
committed
Finished up to challenge 4
1 parent 22bb9b3 commit 96c1fb2

File tree

8 files changed

+89
-188
lines changed

8 files changed

+89
-188
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"python.pythonPath": "C:\\Users\\Tyler\\AppData\\Local\\Programs\\Python\\Python37-32\\python.exe"
3+
}

README

Whitespace-only changes.

challenge1.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Question 1
2+
# Level 1
3+
4+
# Question:
5+
# Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,
6+
# between 2000 and 3200 (both included).
7+
# The numbers obtained should be printed in a comma-separated sequence on a single line.
8+
9+
10+
for i in range(2000, 32001):
11+
if i%7 == 0 and i%5 != 0:
12+
print(i, end=',')
13+
14+
15+
16+
17+
18+
19+

challenge2.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Question 2
2+
# Level 1
3+
4+
# Question:
5+
# Write a program which can compute the factorial of a given numbers.
6+
# The results should be printed in a comma-separated sequence on a single line.
7+
# Suppose the following input is supplied to the program:
8+
# 8
9+
# Then, the output should be:
10+
# 40320
11+
12+
number = int(input("What number? "))
13+
total = number
14+
for i in range((number-1), 1, -1):
15+
total *= i
16+
17+
print('Total = ' + str(total))
18+
19+
#other solution
20+
def fact(x):
21+
if x == 0:
22+
return 1
23+
return x * fact(x - 1)
24+
25+
x=int(input())
26+
print (fact(x))

challenge3.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Question 3
2+
# Level 1
3+
4+
# Question:
5+
# With a given integral number n, write a program to generate a dictionary that contains (i, i*i) such that is an integral number between 1 and n (both included). and then the program should print the dictionary.
6+
# Suppose the following input is supplied to the program:
7+
# 8
8+
# Then, the output should be:
9+
# {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64}
10+
11+
a = {}
12+
13+
def todict(x):
14+
for i in range(1, (x+1)):
15+
a[i] = i*i
16+
print (a)
17+
18+
number = int(input("Number: "))
19+
20+
todict(number)

challenge4.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Question 4
2+
# Level 1
3+
4+
# Question:
5+
# Write a program which accepts a sequence of comma-separated numbers from console and generate a list and a tuple which contains every number.
6+
# Suppose the following input is supplied to the program:
7+
# 34,67,55,33,12,98
8+
# Then, the output should be:
9+
# ['34', '67', '55', '33', '12', '98']
10+
# ('34', '67', '55', '33', '12', '98')
11+
12+
txt = input('Enter string: ')
13+
14+
x = txt.split(',')
15+
y = tuple(x)
16+
17+
print(x[:2])
18+
print(x[2:])
19+
print(x[:-2])
20+
print(x[0:2])
21+
print(y)

python contents.docx

-74.5 KB
Binary file not shown.

python contents.txt

Lines changed: 0 additions & 188 deletions
This file was deleted.

0 commit comments

Comments
 (0)