Skip to content

Commit faeb815

Browse files
committed
added more problem
1 parent 47bdb45 commit faeb815

9 files changed

+447
-49
lines changed

Easy-ones/Floor-Division.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,53 @@ result = num1//num2
2424
print(result)
2525
```
2626

27-
**[Try It:](/#)**
27+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
2828

29-
> to be continued...
29+
#### S-4: Explanation
30+
When you divide one number by another you get two things. One is called the integer part of the division. Another is the remainder.
31+
32+
To get the quotient (result without the remainder), you can use two-division symbols.
33+
34+
print(37//10)
35+
36+
#### S-5: Think different
37+
Another alternative approach is to use the floor method from the math module. If you pass a number with a fraction to the math.floor function, it will return you the integer part of the number.
38+
39+
For example,
40+
```python
41+
import math
42+
result = math.floor(3.4)
43+
print(result)
44+
```
45+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
46+
47+
#### S-6: Alternative Solution
48+
Now, you can use the floor function to get the floor the division. Like below-
49+
```python
50+
import math
51+
num1 = int(input('Enter the first number: '))
52+
num2 = int(input('Enter the second number: '))
53+
54+
result = math.floor(num1//num2)
55+
print(result)
56+
```
57+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
58+
59+
#### S-7: Quiz
60+
How will you get a floor division?
61+
62+
1. //
63+
2. /
64+
3. %
65+
66+
**The answer is: 1**
67+
68+
#### S-8: Take Away
69+
Use // to get floor division.
70+
71+
 
72+
[![Next Page](../assets/next-button.png)](Temporary-variable.md)
73+
 
3074

3175
###### tags: `programmig-hero` `python` `float` `int` `math`
3276

Easy-ones/Math-Power.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ Take two numbers from the users. Calculate the result of second number power of
1212

1313
**result = 4**3**
1414

15-
1615
#### S-3: Solution
17-
1816
```python
1917
base_num = int(input('Give me the base number: '))
2018
power_num = int(input('Give me the power number: '))
2119
result = base_num ** power_num
2220
print('Your result is: ', result)
2321
```
2422

25-
**[Try It:](/#)**
26-
 
23+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
24+
2725
#### S-4: Think Different
2826
Python has a built-in function named pow [blue]. The pow is a short form of the word power. And you can pass 2 numbers to the pow function. It will give you the second number as a power of the first number.
2927

@@ -38,7 +36,7 @@ result = pow(base_num, power_num)
3836
print('Your result is: ', result)
3937

4038
```
41-
**[Try It:](/#)**
39+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
4240

4341
 
4442
[![Next Page](../assets/next-button.png)](Random-Number.md)

Easy-ones/Random-Number.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Create a random number between 0 to 10
1212

1313
##### result = 4**3
1414

15-
1615
#### S-3: Solution
1716

1817
```python
@@ -21,9 +20,7 @@ import random
2120
random_num = random.randint(0,10)
2221
print(random_num)
2322
```
24-
25-
**[Try It:](/#)**
26-
 
23+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
2724

2825
#### S-4: Quiz
2926
How will you generate a random integer number?

Easy-ones/Temporary-variable.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
## 1.5: Swap two variables
3+
4+
**S-1: The problem**
5+
> Swap two variables.<br><br>To swap two variables: the value of the first variable will become the value of the second variable. On the other hand, the value of the second variable will become the value of the first variable.
6+
7+
<details>
8+
<summary><b>S-2: Click Here For Show Hints</b></summary>
9+
<p>To swap two variables, you can use a temp variable.</p>
10+
</details>
11+
<br>
12+
13+
#### S-3: Solution
14+
15+
```python
16+
a = 5
17+
b = 7
18+
print('a, b', a, b)
19+
# swap these two
20+
temp = a
21+
a = b
22+
b = temp
23+
print('a, b', a, b)
24+
```
25+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
26+
27+
## S-4: Shortcut
28+
You can use a python shortcut to swap two variables as well. How this works, would be a little bit tricky for you. So, for now, just remember it.
29+
30+
```python
31+
x = 12
32+
y = 33
33+
print('x, y', x, y)
34+
#swap these two
35+
x, y = y, x
36+
print('x, y', x, y)
37+
```
38+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
39+
40+
#### S-5: Another solution
41+
If both the variable is number, you can apply other tricks. Like the one below-
42+
43+
```python
44+
a = 5
45+
b = 7
46+
print('a, b', a, b)
47+
# swap these two
48+
a = a + b
49+
b = a - b
50+
a = a - b
51+
print('a, b', a, b)
52+
```
53+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
54+
55+
#### S-6: Quiz
56+
How would you swap two variables?
57+
58+
1. Using two temporary variables
59+
2. My family doesn’t permit swapping
60+
3. Use something like: a, b= b, a
61+
62+
**The answer is: 3**
63+
64+
*S-7: Take Away*
65+
Use temp variable to swap two variables. <br>
66+
67+
&nbsp;
68+
[![Next Page](../assets/next-button.png)](#)
69+
&nbsp;
70+
71+
###### tags: `programmig-hero` `python` `float` `int` `math`
72+
73+

Easy-ones/User-input-to-Number.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# 100 Plus Python Coding Problems With Solutions
2+
---
3+
4+
### 1.1: User input to Number
5+
6+
**S-1: The problem**
7+
Take two inputs from the user. One will be an integer. The other will be a float number. Then multiply them to display the output.
8+
9+
<details>
10+
<summary><b>S-2: Click Here For Show Hints</b></summary>
11+
<p>Use input. By default, input gives you a string. Then use int and float to convert the input to a number. And then multiply them. <br><br>That’s it.</p>
12+
</details>
13+
<br>
14+
15+
#### S-3: Solution
16+
```python
17+
int_text = input("Give me an integer number: ")
18+
int_num = int(int_text)
19+
float_text = input("Give me a float number: ")
20+
float_num = float(float_text)
21+
result = int_num * float_num
22+
print("Your result is: ", result)
23+
```
24+
25+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
26+
27+
#### S-4: Shortcut
28+
> You wrote input in one line and then in the next line you used int or float to convert the number. You can write the two lines in one line. Like below
29+
30+
```python
31+
int_num = int(input('Give me an integer number: '))
32+
float_num = float(input('Give me a float number: '))
33+
result = int_num * float_num
34+
print('Your result is: ', result)
35+
```
36+
37+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
38+
39+
#### S-5: Going Forward
40+
Going forward, we will write input and conversion in one line.
41+
42+
#### S-6: Quiz
43+
Which one is used to convert string to a number?
44+
45+
46+
1. number
47+
2. convert
48+
3. int or float
49+
50+
**The answer is: 3**
51+
52+
*S-7: Take Away*
53+
54+
Use int or float to convert user input to a number. <br>
55+
56+
&nbsp;
57+
[![Next Page](../assets/next-button.png)](Math-Power.md)
58+
&nbsp;
59+
60+
###### tags: `programmig-hero` `python` `float` `int` `math`

Number-Related/Average-of-numbers.md

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
## 2.3: Average of numbers
3+
4+
**S-1: The problem**
5+
Take numbers from a user and show the average of the numbers the user entered.
6+
7+
<details>
8+
<summary><b>S-2: Click Here For Show Hints</b></summary>
9+
<p>To solve this problem.
10+
11+
First, ask the user - How many numbers you want to enter?
12+
13+
Then, run a for-loop. Each time, take input from the user and put it in a list.
14+
15+
Once you get all the numbers, you can send the list to the sum function. The sum function will add all the numbers and give you the total.
16+
17+
Finally, divide the total by the number of elements the user entered.
18+
19+
That’s it, you will get the answer.
20+
21+
Want to try it yourself first? Go to the code editor and try it.
22+
</p>
23+
</details>
24+
<br>
25+
26+
**[Try It:](/#)**
27+
28+
29+
#### S-3: Solution
30+
```python
31+
len = int(input("How many numbers do you want to enter? "))
32+
33+
nums = []
34+
35+
for i in range(0, len):
36+
element = int(input("Enter element: "))
37+
nums.append(element)
38+
39+
total = sum(nums)
40+
avg = total/len
41+
print("Average of elements you entered",round(avg,2))
42+
```
43+
44+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
45+
46+
#### S-4: Explanation
47+
First, ask the user how many numbers he/she wants to enter. Once we have the number, run a for loop. To collect the numbers.
48+
49+
While collecting the numbers, we are adding those in the list called nums.
50+
51+
Then we pass the list to the sum function. The sum function returns us the sum of each number in the list
52+
53+
Eventually, we divide the total by the number of elements to get the average.
54+
55+
#### S-5: Another Solution
56+
```python
57+
len=int(input("How many numbers you want to enter: "))
58+
59+
total = 0
60+
61+
for i in range(0,len):
62+
elem=int(input("Enter element: "))
63+
total += elem
64+
65+
avg = total/len
66+
print("Average of elements you entered",round(avg,2))
67+
```
68+
**[Try It:](/https://play.google.com/store/apps/details?id=com.learnprogramming.codecamp)**
69+
70+
#### S-6: Explanation
71+
In the second approach, other than directly adding to the list, we are adding it to the total variable. And then we are dividing it by the number of input the user entered.
72+
73+
#### S-7: Take Away
74+
> To get the average, calculate the total and divide by the number of elements.
75+
76+
&nbsp;
77+
[![Next Page](../assets/next-button.png)](../README.md)
78+
&nbsp;
79+
80+
###### tags: `programmig-hero` `python` `float` `int` `math`

0 commit comments

Comments
 (0)