0% found this document useful (0 votes)
3 views

Python Basics

The document outlines a series of programming tasks and projects primarily focused on Python and Django, including finding maximum numbers, determining even or odd, greeting users based on time, calculating ticket prices based on age, and classifying age groups. It also details steps for setting up Django projects, creating models, handling user registration, and working with APIs for data retrieval. Additionally, it includes tasks related to creating templates, managing grocery and movie databases, and performing various data manipulations.

Uploaded by

ritasiddhpura2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Python Basics

The document outlines a series of programming tasks and projects primarily focused on Python and Django, including finding maximum numbers, determining even or odd, greeting users based on time, calculating ticket prices based on age, and classifying age groups. It also details steps for setting up Django projects, creating models, handling user registration, and working with APIs for data retrieval. Additionally, it includes tasks related to creating templates, managing grocery and movie databases, and performing various data manipulations.

Uploaded by

ritasiddhpura2
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 84

TASKS :

1. FIND MAX AMONG THREE NUMBERS.

2. FIND GIVEN NUMBER IS EVEN OR ODD.

3. CREATE A PROGRAM WHICH GREETS THE USER ACCORDING TO CURRENT


TIME.

CONDITIONS :
IF TIME IS ( 6 TO 12 ) THEN GOOD MORNING
IF TIME IS (12 TO 4) GOOD AFTERNOON
IF TIME IS > 4 GOOD EVENING.

4. CREATE PYTHON PROGRAM WHICH CALCULATE TICKET PRICE BASED ON THE


AGE

CONDITIONS:
IF AGE IS BELOW 3 THEN NO TICKET PRICE WILL TAKEN
IF AGE IS BETWEEN 4 TO 12 THEN DISCOUNT RATE IS 10%
IF AGE IS ABOVE THE 12 THEN DISCOUNT RATE IS 5%.

5. CREATE PROGRAM WHICH WILL CLASSIFY THE AGE BASED ON THE AGE
GIVEN BY USER

CONDITIONS :

infant: 0–1 years


Toddler: 2–4 years

Child: 5–12 years

Teen: 13–19 years

Adult: 20–39 years

Middle age adult: 40–59 years

Senior adult: 60+ years


STEP 1 : pip install django

STEP 2: django-admin startproject (project name) .

STEP 3 : django-admin startapp (appname)

STEP 4 : register app > myproject > settings.py


installed apps = [
..,
'myapp'
]
STEP 5 : python manage.py migrate

STEP 6: python manage.py runserver

STEP 7 : python manage.py createsuperuser

username
email
password
confirm password
-----------------------------------------------------------------------------------------------------------
Create new python project:
Django project: University
Django app: College
Superuser: username: Principal| password: Principal@123

Login Principal and add Department Heads from users.

Username: BCAhead
Password: BCA@head

Username: BCOMhead
Password: BCOM@head

✅ ✅ ❌
Username active staff superuser extra

✅ ✅ ✅
BCAhead Can view users
BCOMhead -
project name : task
django project : flipkart
django app1 : userapp
django app2 : flipkartapp
django app3 : deliveryboy

superusers :1) filpkartadmin | flipkart@123


2) flipkartsubadmin | flipkartsub@123

login into flipkart admin and add three users:


1) gaurav | boy1@123
2) aman | boy2@123

✅ ✅ ❌
Username active staff superuser extra

✅ ✅ ❌
gaurav -
aman -
LIST TASKS :

❖ Grocery Shopping List:


➢ For Example : ["milk", "eggs", "bread", "butter"]
➢ Create a list to store grocery items.
➢ Add and remove items from the list.
➢ Sort the list alphabetically.
➢ Find the total number of items in the list.
➢ Check if a specific item is in the list.
❖ Movie Database:
➢ Create a list of favorite movies.
➢ Add and remove movies from the list.
➢ Sort the movies list.
➢ Check if a specific movie is in the list.
➢ Count the total number of movies in the list.
➢ Slice the new movies from the last three movies of your list.

❖ Weather Data Analysis:


➢ Create a list of daily temperatures for a week.
➢ Calculate the average temperature for the week.
➢ Find the highest and lowest temperature.
➢ Count the number of days with temperatures above a 45.
➢ Sort the temperatures in ascending order.
Models.py
Admin.py
Model created successfully.
TASK:
Pythonproject: modelpractice
Django project: university
Django app: collegeapp
Superuser : username: infoadmin | password: 123

Create two models as per following.

Collegedetail

name

address

phone

email

established_year

city

Coursedetail

name

duration

seats

fees
Dictionary tasks : click me

Exercise 4 :

authors = {
"F. Scott Fitzgerald": ["The Great Gatsby", "Tender Is the Night", "The Beautiful and
Damned"],
"Harper Lee": ["To Kill a Mockingbird", "Go Set a Watchman", "To Kill a Mockingbird: 50th
Anniversary Edition"],
"George Orwell": ["1984", "Animal Farm", "Homage to Catalonia"],
"Jane Austen": ["Pride and Prejudice", "Sense and Sensibility", "Emma"],
"J.D. Salinger": ["The Catcher in the Rye", "Franny and Zooey", "Nine Stories"],
"J.K. Rowling": ["Harry Potter and the Philosopher's Stone", "Harry Potter and the Chamber of
Secrets", "Harry Potter and the Prisoner of Azkaban", "Harry Potter and the Goblet of Fire"],
"Agatha Christie": ["Murder on the Orient Express", "The Murder at the Vicarage", "The ABC
Murders", "Death on the Nile"]
}

Print Total Number of Authors

Print total numbers of books of Harper Lee

Print All Books by a George Orwell Author with the Author name
// output:- Author:- George Orwell Books:- 1984, Animal Farm, Homage to Catalonia

Check if an Author J.K. Rowling Exists in the Collection if present the write present else not
present

List All Books with Authors

print the 1984


INFOLABZ IT SERVICES PVT. LTD.

Course : Python ( Django )


Topics to be covered : DJANGO MODEL DIFFERENT FIELDS

Python Project: advancedmodels


Django Project: carshowroom
Django App : cars
Superuser: username: infolabzadmin | password: 123

Step 1: Create a model as per following:

Cartable

Make Dropdown: honda , toyota , nissan , ford

Fuel_Type Dropdown: Gasoline , Hybrid , electric , diesel ,Natural Gas

Model

Year

Price

Available BooleanField

Image URL URLField

Description
Storetable

Name

Address

Phone Number

Purchasetable

Customer Name

Car Make Dropdown: honda , toyota , nissan , ford

Car Model CharField (max_length=100)

Store Dropdown: Ahmedabad , Baroda , Surat , Rajkot

Purchase Date DateTimeField (auto_now_add=True)

Price Paid
Model Practice Task :

Django Practice Models Task :


STEP 1 : CREATE TEMPLATES FOLDER INSIDE THE APP

STEP 2 : CREATE HTML PAGES INSIDE THE TEMPLATES FOLDER


STEP 3 : CREATE VIEW AFTER CREATING TEMPLATES
STEP 4 : CREATE URLS.PY FILE INSIDE THE APP.

STEP 5 : CREATE URLS ACCORDING TO YOUR VIEWS


STEP 6 : INCLUDE APP URLS INSIDE THE PROJECT URLS
STEP 7 : RUN SERVER
Taks 2:

Create 5 pages as follow:

First.html
Second.html
Third.html
Forth.html
Five.html

Every page must have one image. Each page should be linked with the
previous and next page.

First page > second page


First page < Second page > third page
Second page < third page > forth page
Third page < forth page > fifth page
Forth page < fifth page
Task : EventManagement
Objective:
Create an event management site with the following pages:

1. Home Page
2. Event Page
3. Create Event Page
4. Event Categories Page
5. Contact Page

CONVERT THE FOLLOWING TEMPLATE IN DJANGO


TEMPLATE DOWNLOAD LINK

Download template and unzip it to the folder.


Click here to Download

Download template and unzip it to the folder.


Click here to Download
Create a menu program basic calculator

Take two inputs number1 and number 2.

Create 5 options which ask for an


operation from the user.

1. For addition
2. For subtraction
3. For division
4. For multiplication
5. For exit

Perform operation based on selected


option and display output.
TASK:
Download this template from link: download
flight_booking_form-web_Free20-01-2018_579098314 (1).zip
Load this template in django project.

After loading the template perform form to variable for the form.
Download Following Form and perform form to variable:

https://drive.google.com/file/d/1CFu7AEq4MftZwkYaiopm_-0SNCjbGR
5D/view?usp=sharing

Booking Form

https://drive.google.com/file/d/14sIO0ySZolnX7m3EODEia
pvQ9GHXgWI0/view?usp=sharing
Perform Form To Variable On following form and
print to another page.

https://drive.google.com/file/d/1nynohO2yS7Uh5
pv08D-du5nfM2ZmBjQg/view?usp=sharing
index.html
Register The User From Following Registration
Form :

https://drive.google.com/file/d/1YVj9DSk5XPkZU
PwBHjC7jOSfyAag7otq/view?usp=sharing

Job Application Form :

https://drive.google.com/file/d/1JkC8e26jYsZFqy
zmXK7iiTCiTfjM43IH/view?usp=sharing

Login Signup Forms Ui


https://themewagon.com/blog/loginsign-up-form-
to-compliment-your-website/
Study Course Template Link:

https://drive.google.com/file/d/1O_uN0jzKOgebSEUuI861
ngQsyx4A1jNL/view?usp=sharing
Dictionary tasks:

cart = {"Laptop": {"price": 1000,"quantity": 1,"categories":


["Electronics", "Computers"],"manufacturer": "TechCorp","reviews":
[{"user": "Alice", "rating": 5}, {"user": "Bob", "rating": 4.5}]},"Mouse":
{"price": 50,"quantity": 2,"categories": ["Electronics",
"Accessories"],"manufacturer": "GadgetPro","reviews": [{"user": "Charlie",
"rating": 4}, {"user": "Dave", "rating": 4.5}]},"Keyboard": {"price":
80,"quantity": 1,"categories": ["Electronics",
"Accessories"],"manufacturer": "GadgetPro","reviews": [{"user": "Eve",
"rating": 4.5}, {"user": "Frank", "rating": 4}]},"Headphones": {"price":
200,"quantity": 1,"categories": ["Electronics", "Audio"],"manufacturer":
"SoundMax","reviews": [{"user": "Grace", "rating": 5}, {"user": "Heidi",
"rating": 4.8}]}}

Print total numbers of keys.


Print total numbers of values.
Print Pair of key values.
Print the categories values of the keyboard.
Identify the product by Product Manufacturer SoundMax.
Count the total reviews of the keyboard.
Print the rating of all products.
Calculate the avg ratings of the mouse.
Print the ratings of the user “Grace”.
Blogs Site Template :
https://drive.google.com/file/d/1ie9CjX6nKG7PDo
sTk425v_dQOr91kKtk/view?usp=sharing
API LINK : https://inshorts.vercel.app/news/top

1. pip install requests


2. fetch api data
3. convert data in json format
4. access the data

print the data


print all keys
print all values
print all key values pairs
count total numbers of main keys
count total numbers of main values
access the main keys values
find the type of value present at key
access the data key
find the keys presnt in data
count the length of the data keys
access data keys values
print all data of news api
API explanation doc :
https://www.learnpython.dev/02-introduction-to-python/190-apis/00-requests-and-responses/
https://api.coindesk.com/v1/bpi/currentprice.json

print all main keys


print USD rate of bitcoin
print EUR rate of bitcoin
print GBP rate of bitcoin

https://api.dictionaryapi.dev/api/v2/entries/en/hello

1) How many main keys are there in this API


2) Print name of all main keys
3) How many meanings did you find ?
4) Print meaning of hello from the API
https://isro.vercel.app/api/spacecrafts

1) Print all main keys


2) Count total numbers of spacecrafts
3) Print HAMSAT spacecraft
NEWS API DISPLAY ON TEMPLATE

Topics :

1) How to fetch data from api and use that data into the html
template ?
ans.

Step 1 : Get the URL of API


Step 2 : Create a new project and set all settings
Step 3 : install and import the requests module into your program
Step 4 : write the following code any your required views
Import requests
Url = request.get(“url of API”)
Json_data = url.json()
Context = { “data” : json_data [‘key’] [‘key’] }
Render (“page.html”, view.viewname, context)
Step 6 : Print the data on the destination html page using for loop
and“{{}}” brackets.
News template page :
https://drive.google.com/file/d/14hjaV9r8oBU6cnf
GX82uSaCZgyF8YsgP/view?usp=sharing

API LINK : https://inshorts.vercel.app/news/top


Tasks :

Print all spacecraft on the html page using a html


table and also enhance the ui of the html page
using css.

ISRO API:
https://isro.vercel.app/api/spacecrafts

BITCOIN API :

Print BITCOIN Rate of USD, EUR , GBP on the


html template and the html page should be
refreshed automatically after 3 seconds to
display the updated rate of the bitcoin.

https://api.coindesk.com/v1/bpi/currentprice.json
RTO API:

url = "https://indian-rtos-names-search.p.rapidapi.com/rtos"
headers = {
"x-rapidapi-key":
"d1cdc518d8mshf21c5dc9e4b20c4p11ad42jsn8a083e29935a",
"x-rapidapi-host": "indian-rtos-names-search.p.rapidapi.com"
}
response = requests.get(url, headers=headers)

print total numbers of main keys


count main keys
print all data in table format

POST OFFICE PIN CODE API


https://api.postalpincode.in/pincode/380001

Print all post offices in table format.


REST COUNTRIES

https://rest-countries10.p.rapidapi.com/countries

headers = {
"x-rapidapi-key":
"d1cdc518d8mshf21c5dc9e4b20c4p11ad42jsn8a083e29935a",
"x-rapidapi-host": "rest-countries10.p.rapidapi.com"
}

Mutual Funds schemes :


https://api.mfapi.in/mf

Print all schemes into table format.


Dynamic Pincode Post Office:

COVID19 API:

https://data.covid19india.org/data.json

Find and print main keys


Count total main keys
Print daily data in different tables.
Print state wise data in different tables.
Word Api:

https://api.dictionaryapi.dev/api/v2/entries/en/hello

Make dynamic this api

https://themewagon.com/theme-price/free/

Products api:
https://dummyjson.com/products

https://dummyjson.com/products/search?q={categ
ory}

https://dummyjson.com/products/categories

https://dummyjson.com/products/{id}

https://dummyjson.com/products/category/{categ
ory}
Jokes Template :

https://drive.google.com/file/d/10ILSmyyGo2n6dgxGJv2-9
1LcZSEsZNgn/view?usp=sharing

Recipes api

https://dummyjson.com/recipes

You might also like