Shayan Milanistafibonachi
a = 0
b = 1
print(0)
while b <1000:
print(b)
a,b = b, a+b
sum = 1
i= 0
while sum <= 300:
sum= sum + i
if sum > 300:
break
print(sum)
i= i +1
----------------------------------------------------------------
nterms = int(input("How many terms? "))
n1, n2 = 0, 1
count = 0
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto",nterms,":")
print(n1)
else:
print("Fibonacci sequence:")
while count < nterms:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
---------------------------------------------------------------------
stars
def star(n):
for i in range(1, n + 1):
print("*" * i)
for i in range(n - 1, 0, -1):
print("*" * i)
star(5)
------
for i in range(1, 5):
print("*" * i)
for i in range(5, 1, -1):
print("*" * i)
s = "*"
for i in range(5):
print(s)
s += "*"
--------------
lozi
height = 5
for i in range(1, height + 1):
if i <= (height + 1) // 2:
stars = '*' * (2 * i - 1)
else:
stars = '*' * (2 * (height - i) + 1)
print(stars.center(2 * height - 1))
----------------------------------------------
بزرگ ترین بین چند عدد
p = int(input("Enter number: "))
b = 0
while p > 0:
c = p % 10
if c > b:
b = c
p = p // 10
print(b)
چند رقمی بودن
p = int(input("Enter number: "))
b = 0
while p > 0:
p = p // 10
b = b + 1
print(b)
server
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("localhost", 14200))
s.listen(1)
#Waiting For a Connection
connection, client = s.accept()
print(client, 'Connected')
data = connection.recv(32)
print('Received "' + data.decode() + '"')
connection.send("Message Received!".encode())
connection.close()
client
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#connecting
s.connect(("localhost", 14200))
message = "Hello"
s.send(message.encode())
data = s.recv(32)
print(data.decode())
#Connection Closed
s.close()