Skip to content

Commit a3f837f

Browse files
authored
Update PythonQuestions.md
1 parent 43a2bb6 commit a3f837f

1 file changed

Lines changed: 100 additions & 0 deletions

File tree

PythonQuestions.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,103 @@
1+
Question:
2+
Swap Two Number
3+
4+
Program
5+
```
6+
a=25
7+
b=10
8+
9+
#for swap
10+
a,b=b,a
11+
print(a)
12+
print(b)
13+
```
14+
output:
15+
```
16+
10
17+
25
18+
```
19+
Question:
20+
Get largest number from 2 numbers using ternary operator
21+
22+
Syntax:
23+
```
24+
<expression 1> if <condition> else <expression 2>
25+
```
26+
Program:
27+
```python
28+
num1=50
29+
num2=40
30+
large=num1 if num1>num2 else num2
31+
print(large)
32+
```
33+
34+
Output:
35+
```
36+
50
37+
```
38+
39+
40+
Question:
41+
Sort string numbers in array
42+
43+
44+
Program:
45+
```python
46+
#using list comprehension
47+
lst=["6","8","3","9"]
48+
lst=[int(i) for i in lst]
49+
lst.sort()
50+
print(lst)
51+
52+
#using map
53+
lst=["6","8","3","9"]
54+
lst=list(map(int,lst))
55+
lst.sort()
56+
print(lst)
57+
58+
#using lambda
59+
lst=["6","8","3","9"]
60+
lst=sorted(lst,key=lambda x:int(x))
61+
print(lst)
62+
```
63+
64+
Output:
65+
````
66+
[3, 6, 8, 9]
67+
[3, 6, 8, 9]
68+
['3', '6', '8', '9']
69+
```
70+
71+
Question :
72+
Find N-th Number PrimeNumber
73+
74+
Program
75+
```python
76+
L = [2,3]
77+
n = int(input())
78+
k = 4
79+
80+
while k>0:
81+
if len(L) == n:
82+
break
83+
for i in L:
84+
if k%i==0:
85+
break
86+
else:
87+
L.append(k)
88+
k+=1
89+
90+
print(L[-1])
91+
```
92+
93+
Output:
94+
```
95+
10
96+
29
97+
```
98+
99+
100+
1101
Question 1
2102
```
3103
Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5,

0 commit comments

Comments
 (0)