Python Using AI
Python Using AI
Prompt 1
Assume i'm a complete beginner in Python, who has never written a code, tell a simple line to run
print("Hello, World!")
Prompt 2
I have 10 days of holidays, and I want to use these 10 days to learn Python, and I have 2 hours of free
time every day, now prepare daily and hourly planner so that I'm at least good with Python basics
Prompt 3
Please give me a list of 10 MCQs on Python basics, make the options very tricky to choose
Prompt 4 Now give me 30 more of these and make the level to medium
Prompt 5
Prompt 6
Error code
wallet_amount = 100
ticket_price = 120
else:
print("Go home"
Corrected code
wallet_amount = 100
ticket_price = 120
if wallet_amount > ticket_price:
else:
print("Go home")
Prompt 7 I started learning IF ELSE in Python, now help me understand about this
concept from scratch, with some examples in real life, assume you are
if toy_color == "red":
else:
Prompt 8
I want to create a world map visual in Python, if I hover over a country it should display that country
name
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('<https://raw.githubusercontent.com/plotly/datasets/master/
2014_world_gdp_with_codes.csv>')
fig = go.Figure(data=go.Choropleth(
locations = df['CODE'],
z = df['GDP (BILLIONS)'],
text = df['COUNTRY'],
colorscale = 'Blues',
autocolorscale=False,
reversescale=True,
marker_line_color='darkgray',
marker_line_width=0.5,
))
fig.update_layout(
title_text='World Map',
geo=dict(
showframe=False,
showcoastlines=True,
projection_type='equirectangular'
),
annotations = [dict(
x=0.55,
y=0.1,
xref='paper',
yref='paper',
showarrow = False
)]
fig.show()
How to set up Visual Studio Code?
1. Download “Visual Studio Code” - Latest version for Windows / Mac / Linux
6. In case you get any errors → please run this command → pip install streamlit
Prompt 9 can you help me build a website in Python using Streamlit, it has to do the following: it should
be a calculator with basic add, minus, multiply, and divide, it should have buttons to click as well
import streamlit as st
if operation == '+':
st.title("Simple Calculator")
# Input fields
with col2:
with col3:
if st.button("\\u2716"): # Multiplication X
with col4:
# Display result
if 'result' in locals():
st.success(f"Result: {result}")
Prompt 10
Write a Python script to scrape static content from a website. Use the URL http://books.toscrape.com/ to
scrape book titles and their prices. Parse the webpage using BeautifulSoup and print the data in a clean,
readable format. Ensure the script works for static, non-time-sensitive pages, and include error handling
for HTTP requests. Additionally, provide an option to save the scraped data to a CSV file.
import requests
url = "<http://books.toscrape.com/>"
# Send an HTTP GET request to the URL
response = requests.get(url)
book_data = []
title = book.h3.a['title']
import csv
# Save the data to a CSV file
writer.writeheader()
writer.writerows(book_data)
Prompt 11
can you help me scrape the T20I overall runs from this URL:
https://www.cricbuzz.com/profiles/1413/virat-kohli
import requests
def scrape_t20i_runs(url):
response = requests.get(url)
if response.status_code == 200:
if table:
rows = table.find_all('tr')
# Look for the T20I row
cols = row.find_all('td')
t20i_runs = cols[4].text.strip()
return t20i_runs
return None
else:
return None
url = "<https://www.cricbuzz.com/profiles/1413/virat-kohli>"
t20i_runs = scrape_t20i_runs(url)
if t20i_runs:
else:
Prompt 11
Prompt 12
https://bolt.new/