In [ ]:
## CHAPTER 2
In [1]:
# Enter yearly interest rate
annualInterestRate = eval(input(
  "Enter annual interest rate, e.g., 8.25: "))
monthlyInterestRate = annualInterestRate / 1200

# Enter number of years
numberOfYears = eval(input(
  "Enter number of years as an integer, e.g., 5: "))
    
# Enter loan amount
loanAmount = eval(input("Enter loan amount, e.g., 120000.95: "))
    
# Calculate payment
monthlyPayment = loanAmount * monthlyInterestRate / (1
  - 1 / (1 + monthlyInterestRate) ** (numberOfYears * 12))
totalPayment = monthlyPayment * numberOfYears * 12

# Display results
print("The monthly payment is", int(monthlyPayment * 100) / 100)
print("The total payment is", int(totalPayment * 100) /100)
Enter annual interest rate, e.g., 8.25: 9
Enter number of years as an integer, e.g., 5: 10
Enter loan amount, e.g., 120000.95: 500000
The monthly payment is 6333.78
The total payment is 760054.64
In [6]:
# Enter the first point with two double values
x1, y1 = eval(input("Enter x1 and y1: "))

# Enter the second point with two double values
x2, y2 = eval(input("Enter x2 and y2: "))
 
# Compute the distance
distance = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) ** 0.5
    
print("The distance between the two points is", distance) 
Enter x1 and y1: 1,1
Enter x2 and y2: 40,40
The distance between the two points is 55.154328932550705
In [ ]:
import turtle

# Prompt the user for inputing two points
x1, y1 = eval(input("Enter x1 and y1 for Point 1: "))
x2, y2 = eval(input("Enter x2 and y2 for Point 2: "))
              
# Compute the distance
distance = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

# Display two points and the connecting line
turtle.penup()
turtle.goto(x1, y1) # Move to (x1, y1)
turtle.pendown()
turtle.write("Point 1") 
turtle.goto(x2, y2) # draw a line to (x2, y2)
turtle.write("Point 2")

# Move to the center point of the line
turtle.penup()
turtle.goto((x1 + x2) / 2, (y1 + y2) / 2) 
turtle.write(distance)

turtle.done() 
Enter x1 and y1 for Point 1: 1,1
Enter x2 and y2 for Point 2: 200,200
In [ ]:
 
In [1]:
## CHAPTER  3
In [1]:
min(3,6,8,9)
Out[1]:
3
In [3]:
import math
math.sin(30)
Out[3]:
-0.9880316240928618
In [7]:
x = math.radians(90)
math.sin(x)
Out[7]:
1.0
In [ ]:
 
In [4]:
import math # import Math module to use the math functions
 
# Test algebraic functions
print("exp(1.0) =", math.exp(1))
print("log(3.78) =", math.log(math.e))
print("log10(10, 10) =", math.log(10, 10))
print("sqrt(4.0) =", math.sqrt(4.0))
 
# Test trigonometric functions
print("sin(PI / 2) =", math.sin(math.pi / 2))
print("cos(PI / 2) =", math.cos(math.pi / 2))
print("tan(PI / 2) =", math.tan(math.pi / 2))
print("degrees(1.57) =", math.degrees(1.57))
print("radians(90) =", math.radians(90))
exp(1.0) = 2.718281828459045
log(3.78) = 1.0
log10(10, 10) = 1.0
sqrt(4.0) = 2.0
sin(PI / 2) = 1.0
cos(PI / 2) = 6.123233995736766e-17
tan(PI / 2) = 1.633123935319537e+16
degrees(1.57) = 89.95437383553924
radians(90) = 1.5707963267948966
In [3]:
import math

x1, y1, x2, y2, x3, y3 = eval(input("Enter six coordinates of three points \
separated by commas like x1, y1, x2, y2, x3, y3: "))
 
a = math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))
b = math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3))
c = math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))

A = math.degrees(math.acos((a * a - b * b - c * c) / (-2 * b * c)))
B = math.degrees(math.acos((b * b - a * a - c * c) / (-2 * a * c)))
C = math.degrees(math.acos((c * c - b * b - a * a) / (-2 * a * b)))

print("The three angles are ", round(A * 100) / 100.0,  
    round(B * 100) / 100.0, round(C * 100) / 100.0)
Enter six coordinates of three points separated by commas like x1, y1, x2, y2, x3, y3: 1,1,400,400,600,1
The three angles are  45.0 71.62 63.38
In [ ]:
 
In [9]:
a = 01010000 # 30 in decimal 
  File "/var/folders/9h/3x3_v4p142v1d8n7zxt_wg0h0000gn/T/ipykernel_12531/2331456752.py", line 1
    a = 01010000
               ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
In [10]:
# A byte consists of 8 bits
In [11]:
2 ** 8
Out[11]:
256
In [ ]:
# Python uses 2 bytes (16 bits)
In [ ]:
 
In [13]:
ord("0")
Out[13]:
48
In [14]:
ord("X")
Out[14]:
88
In [15]:
ord("x")
Out[15]:
120
In [ ]:
 
In [16]:
chr(120)
Out[16]:
'x'
In [17]:
chr(88)
Out[17]:
'X'
In [ ]:
 
In [26]:
s1 = "Ali \' \ Veli "
s1
Out[26]:
"Ali ' \\ Veli "
In [ ]:
 
In [12]:
2 ** 16
Out[12]:
65536
In [ ]:
import turtle

turtle.write("\u6B22 \u8FCE \u03b1 \u03b2 \u03b3",font=('Times New Roman',28,'bold') )

turtle.done() 
In [ ]:
 
In [2]:
print("aaaa aaa")
print("bbbbbbb")
aaaa 
 aaa
bbbbbbb
In [ ]:
 
In [7]:
print("AAA", end = ' ')
print("BBB", end = '')
print("CCC", end = ' ***A')
print(" DDD", end = '***')
AAA BBBCCC ***A DDD***
In [8]:
print("Hello World!", end = '') 
print(" My name is Ali") 
Hello World! My name is Ali
In [ ]:
 
In [9]:
s1 = "abc"
s2 = "dfe"
In [10]:
s1 + s2
Out[10]:
'abcdfe'
In [14]:
s1 * 5
Out[14]:
'abcabcabcabcabc'
In [17]:
s1 + 2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/var/folders/9h/3x3_v4p142v1d8n7zxt_wg0h0000gn/T/ipykernel_15540/3454718208.py in <module>
----> 1 s1 + 2

TypeError: can only concatenate str (not "int") to str
In [16]:
s1 + str(2)
Out[16]:
'abc2'
In [14]:
# Compute Change
# Receive the amount 
amount = eval(input("Enter an amount in double, e.g., 11.56: "))

# Convert the amount to cents
remainingAmount = int(amount * 100)

# Find the number of one dollars
numberOfOneDollars = int(remainingAmount / 100)
remainingAmount = int(remainingAmount % 100)

# Find the number of quarters in the remaining amount
numberOfQuarters = int(remainingAmount / 25)
remainingAmount = remainingAmount % 25

# Find the number of dimes in the remaining amount
numberOfDimes = int(remainingAmount / 10)
remainingAmount = remainingAmount % 10

# Find the number of nickels in the remaining amount
numberOfNickels = int(remainingAmount / 5)
remainingAmount = remainingAmount % 5

# Find the number of pennies in the remaining amount
numberOfPennies = remainingAmount

# Display results
print("Your amount", amount, "consists of\n", 
    "\t", numberOfOneDollars, "dollars\n", 
    "\t", numberOfQuarters, "quarters\n",
    "\t", numberOfDimes,  "dimes\n",
    "\t", numberOfNickels, "nickels\n",
    "\t", numberOfPennies, "pennies")
Enter an amount in double, e.g., 11.56: 12.32
Your amount 12.32 consists of
 	 12 dollars
 	 1 quarters
 	 0 dimes
 	 1 nickels
 	 2 pennies
In [ ]:
 
In [18]:
s1 = "Ali"
In [19]:
s1.upper()
Out[19]:
'ALI'
In [20]:
s1.islower()
Out[20]:
False
In [21]:
s1
Out[21]:
'Ali'
In [30]:
s = "\t Welcome \n Ali \n"
s
Out[30]:
'\t Welcome \n Ali \n'
In [31]:
print(s)
	 Welcome 
 Ali 

In [32]:
s1 = s.strip()
In [29]:
s1
Out[29]:
'Welcome \n Ali'
In [35]:
print(format(57.467657, '20.2f'))
print(format(12345678.923, '10.3f'))
print(format(57.4, '10.2f'))
print(format(57, '10.2f'))
               57.47
12345678.923
     57.40
     57.00
In [37]:
print(format(57.467657, '10.2e'))
print(format(0.0033923, '10.2e'))
print(format(57.4, '10.2e'))
print(format(57, '10.2e'))
  5.75e+01
  3.39e-03
  5.74e+01
  5.70e+01
In [38]:
print(format(0.53457, '10.2%'))
print(format(0.0033923, '10.2%'))
print(format(7.4, '10.2%'))
print(format(57, '10.2%'))
    53.46%
     0.34%
   740.00%
  5700.00%
In [39]:
print(format(57.467657, '10.2f'))
print(format(57.467657, '<10.2f'))
     57.47
57.47     
In [40]:
print(format(59832, '10d'))
print(format(59832, '<10d'))
print(format(59832, '10x'))
print(format(59832, '<10x')) 
     59832
59832     
      e9b8
e9b8      
In [43]:
print(format("Welcome to Python", '20s'))
print(format("Welcome to Python", '<30s'))
print(format("Welcome to Python", '>30s'))
Welcome to Python   
Welcome to Python             
             Welcome to Python
In [ ]:
 
In [44]:
s1
Out[44]:
'Welcome \n Ali'
In [ ]:
s1.format
In [ ]:
 
In [4]:
import turtle
t = turtle.Turtle()
 
t.forward(50)
t.right(90)
t.forward(50)
t.right(90)
t.forward(50)

t.right(65)
t.forward(100)
t.penup()
t.forward(50)
t.pendown()
t.forward(200)
     
turtle.done()

try:
    turtle.bye()
except:
    print("bye") 
bye
In [ ]:
 
In [1]:
import turtle

turtle.pensize(3)
turtle.penup()
turtle.goto(-200, -50)
turtle.pendown()
turtle.circle(40, steps = 3) # Draw a triangle

turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.circle(40, steps = 4) # Draw a square

turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.circle(40, steps = 5) # Draw a pentagon

turtle.penup()
turtle.goto(100, -50)
turtle.pendown()
turtle.circle(40, steps = 6) # Draw a hexagon

turtle.penup()
turtle.goto(200, -50)
turtle.pendown()
turtle.circle(40) # Draw a circle

#turtle.done() 
turtle.exitonclick()
In [ ]:
 
In [1]:
import turtle

turtle.pensize(3) # Set pen thickness to 3 pixels
turtle.penup() # Pull the pen up
turtle.goto(-200, -50)
turtle.pendown() # Pull the pen down
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("red")
turtle.circle(40, steps = 3) # Draw a triangle
turtle.end_fill() # Fill the shape

turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("blue")
turtle.circle(40, steps = 4) # Draw a square
turtle.end_fill() # Fill the shape

turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("green")
turtle.circle(40, steps = 5) # Draw a pentagon
turtle.end_fill() # Fill the shape

turtle.penup()
turtle.goto(100, -50)
turtle.pendown()
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("yellow")
turtle.circle(40, steps = 6) # Draw a hexagon
turtle.end_fill() # Fill the shape

turtle.penup()
turtle.goto(200, -50)
turtle.pendown()
turtle.begin_fill() # Begin to fill color in a shape
turtle.color("purple")
turtle.circle(40) # Draw a circle
turtle.end_fill() # Fill the shape

turtle.color("green")
turtle.penup()
turtle.goto(-100, 50)
turtle.pendown()
turtle.write("Cool Colorful Shapes", 
  font = ("Times", 18, "bold"))
turtle.hideturtle()

turtle.done() 
In [ ]:
 
In [2]:
import turtle

t = turtle.Turtle()
w = turtle.Screen()
w.title("ŞANLI SANCAK")         # Başlık
w.setup(width=720,height=420)   # Pencere Boyutu
w.bgcolor("red")                # Arka Plan Kırmızı Yap

# İlk daire
t.up()
t.goto(-100,-100)               # Fare imleci lokasyonu
t.color('white')                # Beyaz renk
t.begin_fill()                  # Beyaz rengi doldur
t.circle(120)                   # Çapı
t.end_fill()

# Hilal yapabilmek için ikinci daire
t.goto(-70,-80)                 # Fare imleci lokasyonu
t.color('red')                  # Kırmızı renk
t.begin_fill()                  # Kırmızı rengi doldur
t.circle(100)                   # Çapı
t.end_fill()                    # Dolguyu Bitir

# Yıldız için hazırlık
t.goto(0,35)
t.fillcolor("white")
t.begin_fill()

# Yıldız için tekrar eden üçgen çizimi
for i in range(5):
    t.forward(150)
    t.right(144)
t.end_fill()

t.goto(-130,-190)
t.color("white")
t.write("@yazilimfuryasi", font=("Verdana", 17,"bold"))

# Fare imleci ekranda durup görüntüyü bozmasın diye uzaklaştırıyoruz :)
t.goto(-999,-0)

# Ekrana tıklayınca programın kapanmasını sağlar.
w.exitonclick()

try:
    turtle.bye()
except:
    print("bye") 
bye
In [ ]: