Posts

Showing posts from June, 2026

Requests and Urllib

REQUESTS:- import requests # url="https://httpbin.org/post" # data={ #     "name":"hari", #     "age":21 # } # response=requests.post(url,data=data) # print(response.text) # response.status_code   # HTTP status code # response.text          # Response body as text # response.content       # Raw bytes # response.json()        # Convert JSON response to Python object # response.headers       # Response headers # GET REQUEST:- # url = "https://jsonplaceholder.typicode.com/posts/1" # response = requests.get(url) # print(response.text)  URLLIB:- import urllib . request import urllib . parse # link="https://jsonplaceholder.typicode.com/posts/2" # response=urllib.request.urlopen(link) # data=response.read() # print(data.decode("utf-8")) # print(data) # POST REQUEST:- # url="https://httpbin.org/post" # data={ #     "name":"Hari", #     "age":23 # } # encoded_data=urlli...

formatted input

#include <iostream> #include <iomanip> using namespace std ; int main () {     // Write C++ code here     float a = 12.33214 ;     cout << a << endl;     cout << fixed << setprecision ( 2 ) << a << endl;     // int b;     // float sal;     // scanf("%d %f",&b,&sal);     // printf("%7d",b);     // cout<<setw(7)<<fixed<<setprecision(2)<<sal<<endl;         // cout << "Start small. Ship something.";     // cout<<setfill("#")<<setw(7)<<23<<endl;     // cout<<setfill('#')<<setw(7)<<23<<endl;     cout << left << setw ( 3 ) << "Hi" ;     cout << right << setw ( 20 ) << "their" ;     return 0 ; }

sql database

  import sqlite3 conn = sqlite3.connect( "mydatabase.db" ) cursor = conn.cursor() cursor.execute( """ CREATE TABLE IF NOT EXISTS students(     id INTEGER PRIMARY KEY AUTOINCREMENT,     name TEXT NOT NULL,     age INTEGER ) """ ) conn.commit() print ( "TABLE CREATED!!" ) data = [     ( "Alice" , 20 ),     ( "Bob" , 22 ),     ( "Charlie" , 19 ),     ( "David" , 21 ),     ( "Eve" , 20 ) ] cursor.executemany( "insert into students(name,age) values(?,?)" ,data) conn.commit() print ( "DATA INSERTED!" ) cursor.execute( "select * from students" ) rows = cursor.fetchall() for r in rows:     print (r) print ( "DISPLAYED THE DATA ABOVE!" ) cursor.execute( "update students set age=? where age=?" ,( 27 , 21 )) conn.commit() cursor.execute( "select * from students" ) rows = cursor.fetchall() for r in rows:     print (r) print ( "DAT...
  # pip install mysql-connector-python import sqlite3 conn = sqlite3 . connect ( "student.db" ) cur = conn . cursor () cur . execute (     """ CREATE TABLE IF NOT EXISTS students(     id INTEGER PRIMARY KEY,     name TEXT,     age INTEGER ) """ ) # cur.execute("INSERT INTO students(name, age) VALUES(?, ?)",("Gunjan", 21)) cur . execute ( "INSERT INTO students(name,age) values ('Gunjan',20)" ) conn . commit () cur . execute ( "SELECT * FROM students where age=20" ) rows = cur . fetchall () for r in rows :     print ( r ) # conn.commit()