https://github.com/chanakyavasantha/learnpython
Learning Resources for python
https://github.com/chanakyavasantha/learnpython
learn-python learning-by-doing python unit-testing
Last synced: 4 months ago
JSON representation
Learning Resources for python
- Host: GitHub
- URL: https://github.com/chanakyavasantha/learnpython
- Owner: chanakyavasantha
- Created: 2023-07-12T08:18:38.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-30T10:40:39.000Z (about 2 years ago)
- Last Synced: 2023-11-30T11:29:26.909Z (about 2 years ago)
- Topics: learn-python, learning-by-doing, python, unit-testing
- Language: Python
- Homepage:
- Size: 5.63 MB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# PYTHON BASICS:
## **range function in python**:

# Learn Python
# Questions on loops in python:
- counting Number of Digits in a given number


- Sum of First n even numbers


- Algorithm for checking whether a given is a prime or not:


#### Questions on loops in python:
- Find Sum of first **n** natural numbers in python
- Optimized Approach

- Better Alogorithms could solve problems in a optimized approach
#### Functions in python:

Function should be defined so that:
- it accepts input
- it gives some ouput
- The input have some specific data type
- The produced will also have some specific data type

- 
- Write a function in python that tells whether a given numbers is an even number:
- 
- 
#### Exercise on Functions:
- Write a fucntion to check , whether a given number is prime.
- Use both Brute Force Approach, and Optimized Approach
```
## Python Program to check whether a given number is prime using Brute Force Approach
n = int(input()) # taking input from user
flag = 0
for i in range(2,n):
if n % i == 0:
flag = 1
break
if flag == 1:
print("The given number is not prime")
else:
print("The gven number is prime")
```
```
## Python Program to check whether a given number is prime using Optimized Approach
import math
n = int(input()) # taking input from user
flag = 0
for i in range(2,int(math.sqrt(n))+1):
if n % i == 0:
flag = 1
break
if flag == 1:
print("The given number is not prime")
else:
print("The gven number is prime")
```
- Write a function that takes two integers as parameters and returns their sum.
```
## Python Program to design a function that returns sum
def SUM(a,b):
return a+b
a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = SUM(a,b)
print(c)
```
- Write a function that takes a list of numbers as input and returns the largest number in the list.
```
## Python Program to design a function that finds maximum in a list
def FindMax(li):
Max = li[0]
for i in range(len(li)):
if li[i] > Max:
Max = li[i]
return Max
li = list(map(int,input().split()))
c = FindMax(li)
print(c)
```
- **ONE LINE CODE**
```
li = list(map(int,input().split()))
c = max(li)
print(c)
```
- Implement a function that reverses a given string.

```
def rev(a):
b = ""
for i in range(len(a)-1,-1,-1):
b += a[i]
return b # b will have reversed string
a = "chanakya"
print(rev(a))
```
```
a = "kushik"
b = a[::-1]
print(b)
```
- Implement a function that takes a list of words and returns a new list with the words sorted in alphabetical order.
```
def SortedList(li):
li.sort()
return li
li = input().split()
Li = SortedList(li)
print(Li)
```
**split Function in python**
**li = list(map(int,input().split()))** How does this work?
- Some Examples on split() function in python

- input() returns a string by default
- split() returns a list, it's argumnent is the seperator , default seperator is space
- input().split() returns a list of string seperated at space
- map type casts a list with given data type. and returns a map object.
- map object could be converted into list by list(map(....
- list(map(int,input().split())) returns a list of integers by mapping strings to their corresponding integer values.
```
li = list(map(int,['2','3','4']))
print(li)
```

- Write a function that removes duplicates from a list

- How Does jupyter notebook Work, How does it stores local variables data, how data is overriden?