0% found this document useful (0 votes)
19 views4 pages

Codes

Uploaded by

waheedkhan111821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Codes

Uploaded by

waheedkhan111821
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

In [ ]: import matplotlib.

pyplot as plt
import numpy as np

# Generate 100 equally spaced values for x from -100 to 100


x = np.linspace(-100, 100, 100)

# Define the quadratic equation, values of coefficients followed by calculation of y


a = 2
b = 5
c = 1
y = a * x**2 + b * x + c

# Following code is new for you. Now we will create a figure which can have several s
# Create a figure and axis object. The name of axis object is ax in our code.
fig, ax = plt.subplots()

# Plot the quadratic equation. The graph line will have green color, thickness as 2 a
ax.plot(x, y, color='green', linewidth=2, marker='o')

# Set the titles of x and y axes


ax.set_xlabel('X Values Range')
ax.set_ylabel('Y Values Range')

# Set the title of the graph


ax.set_title('Graph of Quadratic Equation for Session 2023')

# Show gridlines
ax.grid(True)

# Here we are going to create tick marks on x and y axis. Remember, usually one out o
# Therefore, you should try the code twice, once by plotting tick marks only and once
# Set the x-axis tick marks and y-axis tick marks based on the maximum and minimum va
ax.set_xticks(np.linspace(np.min(x), np.max(x), num=11))
ax.set_yticks(np.linspace(np.min(y), np.max(y), num=11))

# Display the plot


plt.show()

In [ ]: import turtle

# Create a turtle object


pen = turtle.Turtle()

# Move the turtle to the starting position


pen.penup()
pen.goto(-100, 0)
pen.pendown()

# Set the line color and thickness


pen.color("black")
pen.pensize(2)

# Draw the I shape


pen.forward(200)
pen.penup()
pen.goto(-100, -100)
pen.pendown()
pen.forward(200)

# Close the turtle graphics window


turtle.done()
In [ ]: import matplotlib.pyplot as plt

# Define the coordinates of the line


x = [0, 1, 2, 3]
y = [0, 1, 2, 3]

# Plot the line


plt.plot(x, y)

# Display the plot


plt.show()

In [ ]: import pygame

# Initialize Pygame
pygame.init()

# Set the screen dimensions


screen_width, screen_height = 800, 600

# Create the screen


screen = pygame.display.set_mode((screen_width, screen_height))

# Set the line color


line_color = (255, 0, 0) # Red

# Set the starting and ending points of the line


start_point = (100, 200)
end_point = (500, 400)

# Draw the line on the screen


pygame.draw.line(screen, line_color, start_point, end_point, 2)

# Update the screen


pygame.display.flip()

# Wait for user exit


running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# Quit Pygame
pygame.quit()

In [ ]: #Program to solve quadratic equation


a=float(input("Enter value of Coefficient a = "))
b=float(input("Enter value of Coefficient b = "))
c=float(input("Enter value of Coefficient c = "))

disc=b**2-4*a*c

if disc>0:
print("Real Roots")
x1=(-b+(disc)**.5)/(2*a)
x2=(-b-(disc)**.5)/(2*a)
print("Root 1 = ",x1)
print("Root 2 = ",x2)
elif disc==0:
print("Equal Roots")
x1=-b/(2*a)
x2=-b/(2*a)
print("Root 1 = ",x1)
print("Root 2 = ",x2)
else:
print("Complex Roots")
real=-b/(2*a)
imag=((-disc)**0.5)/(2*a)
x1=str(real)+"+"+str(imag)+" i"
x2=str(real)+"-"+str(imag)+" i"
print("Root 1 = ",x1)
print("Root 2 = ",x2)

In [ ]: import turtle

turtle.speed(1)
turtle.penup()
turtle.goto(-50,50)
turtle.pendown()

red = 255
green = 120
blue = 150

turtle.fillcolor(red/255, green/255, blue/255)


turtle.begin_fill()
for _ in range(2):
turtle.forward(100)
turtle.right(90)
turtle.forward(70)
turtle.right(90)
turtle.end_fill()

turtle.done()

In [ ]: import matplotlib.pyplot as plt

L = float(input('Length = '))
W = float(input('Width = '))

x = [0, 0, L, L, 0]
y = [0, W, W, 0, 0]

plt.plot(x,y)
plt.title('Section C ka Rectangle')
plt.xlim(0,max(L,W))
plt.ylim(0,max(L,W))

Area = L * W

print('Area = ',Area)

In [ ]: for _ in range(5):
print ('My name is Dr. Ali')

In [ ]: for i in range(2,17,3):
print ('Current Value is',i)

In [ ]: num = [1,5,95,13]
for i in num:
print ('Current Value is',i)

In [ ]: fruits = ['Apple','Banana','Orange','Mango']
for var in fruits:
print ('Current Value is',var)
In [ ]: number = [1,5,95,12,17]
fruit = ['Apple','Banana','Orange','Mango']

print(number*3)

In [ ]: print('Hello World')

In [ ]: SecD_String = "Hello World"


print(SecD_String[6:])

In [ ]: name = 'Haider'
age = '18'
print('My name is {} and I am {} years old'.format(name,age))

In [ ]: Radius = float(input('Enter the radius (mm): '))


Area = (22/7)*Radius**2
print('Area of circle having radius = {} mm is {} sq.mm'.format(Radius,round(Area,3))

In [ ]: def cirarea(rad):
return 3.14159*rad**2

x = float(input('Enter the radius: '))


ar = cirarea(x)
print('The area of circle having radius {} is {} sq.m.'.format(x,ar))

In [ ]: # Lets define a new function


def greet(Y):
print('Hello '+Y)

# Main Code
A = input('Your Name Plz? ')
greet(A)

In [ ]: # Lets make a funtion to calculate area of circle


def CA(r):
return 3.142*r**2

# Main Code
a = float(input('Radius = '))
b = CA(a)
print('Area of Circle = ',b)
print('Area of Circle = ',CA(a))

You might also like