Open Source is king!



python programming step by step

Hello World ! – Screen Output



print ("Hello World!")


Comments and Clearing The Screen



import os 
os.system('cls')

#comment 

print ("TURHANSOFTTECH")


Variables



import os
os.system('cls')

company = turhansofttech
print (company)


Python Data Types



import os 
os.system('cls')
#data types 
#string 
#Numbers
#Lists
#Tuples
#Dictionaries

forex_symbol = ["EUR/USD", "EUR/JPY", "EUR/GBP", "EUR/CAD"]
print (forex_symbol[0])   # Result EUR/USD
print (forex_symbol[3]) # Result EUR/CAD


print (forex_symbol) # result ["EUR/USD", "EUR/JPY", "EUR/GBP", "EUR/CAD"]

crypto = { 
  "BTC": "16972",
  "ETH": "1260.9", 
  "LTC": "80.10"
}
print (crypto["ETH"])     #  result 1260.9


Strings



import os 
os.system('cls')

dns = "the dns translates internet domain and host names to \"IP adresses!\""
print (dns)

# result
# the dns translates internet domain and host names to "IP adresses!"

ssh = "ssh is a secure way to login \n\"from host A to host B\""

print (ssh)
 #result 
 # ssh is a secure way to login 
 #     "from host A to host B"


String Manipulation



import os 
os.system('cls')

lan = "= Computer connected with one physical location"

print (lan.upper())
# result  COMPUTER CONNECTED WITH ONE PHYSICAL LOCATION


wan = "= COUNTRY TO COUNTRY"
print (wan.lower())
print (wan.title())


#result  country to country
#result Country To Country



ping = "ping Command allows to CHeck the network status of another Computer"
print (ping.capitalize())
print (ping.swapcase()))
print (len(ping))
print (ping[0])
print (ping[1])
print (ping[:3])
print (ping[3:6])
print (ping[3:7])
print (ping[3:len(ping)])
print (ping.split(' '))
print (ping.split(' ')[3].upper())

#results
# Ping command allows to check the network status of another computer
# PING cOMMAND ALLOWS TO chECK THE NETWORK STATUS OF ANOTHER cOMPUTER
# 67
# p
# i
# pin
# g C
# g Co
# g Command allows to CHeck the network status of another Computer
# ['ping', 'Command', 'allows', 'to', 'CHeck', 'the', 'network', 'status', #'of', 'another', 'Computer']
# TO


Math With Python



import os 
os.system('cls')

zahl_1 = 87
zahl_2 = 89

print (2 + 5)
print (135 - 53)
print (100 / 30)
print (23 ** 2)
print (45 % 40)
print ((23 + 45) * 7)
print (zahl_1 + zahl_2)


#result 

# 7
# 82
# 3.3333333333333335
# 529
# 5
# 476
# 176


Floats and Ints



import os 
os.system('cls')

zahl_1 = 1000
zahl_2 = 30
print (zahl_1 / zahl_2)
print(int(zahl_1 / zahl_2))
print(round((zahl_1 / zahl_2), 3))
print(round((zahl_1 / zahl_2), 5))

#result 

# 33.333333333333336
# 33
# 33.333
# 33.33333


Assignment Operators



import os
os.system('cls')

#Assignment Operators 
zahl = 11 
zahl += 1


print (zahl)
print (zahl + 1)

#result 
#12
#13


Lists



import os
os.system('cls')

#List
forex = ["EUR/USD"]
stocks = ["TSLA","MSFT","AAPL"]
crypto = ["BTC","ETH","LTC","XRP","XLM","SPELL", forex, stocks]

print (crypto[0])
print(crypto[6])
print(crypto[7])
print (stocks[1][2])

#results
# BTC
# ['EUR/USD']
# ['TSLA', 'MSFT', 'AAPL']
# F

import os 
os.system('cls')

#Lists 2

protocol = ["HTTP","DNS","FTP","TELNET"]
protocol[0] = "SMTP"
print (protocol)
del protocol[0]
print (protocol)
protocol.append("SSH")
print (protocol)
print (len(protocol))
print (protocol[len(protocol) - 1])

# ['SMTP', 'DNS', 'FTP', 'TELNET']
# ['DNS', 'FTP', 'TELNET']
# ['DNS', 'FTP', 'TELNET', 'SSH']
# 4
# SSH


Tuples



import os 
os.system('cls')
#Tuples 

tuple_1 = ('Linux', "MacOS","Windows")
tuple_2 = ("İOS" , "Android")

tuple_3 = tuple_1 + tuple_2

print (tuple_1[0])
print (tuple_3)
print (tuple_1[0:2])

#results
# Linux
# ('Linux', 'MacOS', 'Windows', 'İOS', 'Android')
# ('Linux', 'MacOS')

import os 
os.system('cls)

# Tuples 

tuple_1 = ('Linux', "MacOS","Windows")
tuple_2 = ("İOS" , "Android")

tuple_3 = tuple_1[0:2] + tuple_2
print (tuple_3)
#result 
#('Linux', 'MacOS', 'İOS', 'Android')


Dictionaries



import os
os.system('cls')

#Dictionaries 

crypto = { 
  "BTC": "16972",
  "ETH": "1260.9", 
  "LTC": "80.10"
}

crypto["BTC"] = "16984"
crypto.update({"LTC": "85.45"})

print(crypto)
#result 
# {'BTC': '16984', 'ETH': '1260.9', 'LTC': '85.45'}


Comparision Operators



import os 
os.system('cls')
#Comparisions Operators 
# ==  
#!=  
#<    
#>  
#<=  
#>=

turhansofttech = "open source is king!" 
print (10 == 10)
print (9 == 10)
print (9 != 10)
print (11 >= 10)
print (10 >= 10)
print ("turhansofttech" == "TURHANSOFTTECH")
print ([1,2,3]  == [1,2,4])

#result 
# True
# False
# True
# True
# True
# False
# False


Conditional Statements



import os
os.system('cls')
#TURHANSOFTTECH - Conditional Statements İf else Elif

zahl = 50
if (zahl > 100):
    print("Ihre Zahl ist größer als 100")

elif (zahl == 50):
    print("Ihre Nummer ist 50 !!!!")

else:
     print("Ihre Zahl ist NICHT größer als 100"

#result 
# import os
os.system('cls')
#TURHANSOFTTECH - Conditional Statements İf else Elif

zahl = 50
if (zahl > 100):
    print("Ihre Zahl ist größer als 100")

elif (zahl == 50):
    print("Ihre Nummer ist 50 !!!!")

else:
     print("Ihre Zahl ist NICHT größer als 100"

#result 
# Ihre Nummer ist 50 !!!!


Multiple Conditional Statements



import os 
os.system('cls')

#Multiple Conditional Statements and , or 

zahl  = 85
if (zahl > 10) and (zahl < 100):
   print ("Ihre Zahl ist größer als 10, aber kleiner als 100!")

#result 
#Ihre Zahl ist größer als 10, aber kleiner als 100!

import os
os.system('cls')
 
zahl = 1
if (zahl > 10) or (zahl == 100) or (zahl == 10):
  print ("Ihre Zahl ist größer als 10, aber kleiner als 100")
#result null


While Loops


import os
os.system('cls')

# while loops TURHANSOFTTECH

zahler = 0
while (zahler < 10):
   print ("Die zahlung ist:  %s"  % zahler)
   zahler +=1
#result 
#Die zahlung ist:  0
#Die zahlung ist:  1
#Die zahlung ist:  2
#Die zahlung ist:  3
#Die zahlung ist:  4
#Die zahlung ist:  5
#Die zahlung ist:  6
#Die zahlung ist:  7
#Die zahlung ist:  8
#Die zahlung ist:  9


For Loops


import os 
os.system('cls')

# TURHANSOFTTECH for loops

graphic_desing_tools = ["Gimp", "İnkscape", "Scribus"]
for x in graphic_desing_tools:
      print(x)

#result
#Gimp
#İnkscape
#Scribus

import os 
os.system('cls')

# for loops 2 -TURHANSOFTTTECH
crypto = { 
  "BTC": "16972",
  "ETH": "1260.9", 
  "LTC": "80.10"
}

for schlussel,wert in crypto.items():
    print(schlussel,wert)

#result 
# BTC 16972
# ETH 1260.9
# LTC 80.10


FizzBuzz! with Python


import os
os.system('cls')

zahler = 0
while (zahler < 100):
    zahler +=1
    if (zahler % 3 == 0) and (zahler % 5 == 0):
        print("%s - FIZZBUZZ!!" % zahler)

    elif (zahler % 3 == 0):
        print("%s - FIZZ!!" % zahler)

    elif (zahler % 5 ==0):
        print("%s -BUZZ!!" % zahler)

    else:
        print(zahler)

Functions


import os 
os.system('cls')

def turhansofttech(Vorname,Nachname):
       print("Hallo %s" % Vorname)
       print("Hallo %s" % Nachname)

       turhansofttech("Mücahit", "Turhan")

def summe(zahl1, zahl2):
     print (zahl1 + zahl2)
     summe (232, 442)


Functions – 2


import os 
os.system('cls')

def  turhansofttech(company):
       return  ("Hallo %s" % company)

date = turhansofttech("TURHANSOFTTECH 2022")
for linux in date:
       print(linux)


Python Modules


import os
import turhansofttech_module
os.system('cls')

print(turhansofttech_module.company("Mücahit"))

turhansofttech_module.py
def company(vorname): 
     return("Hallo %s" % vorname)


Python Classes



import os
os.system('cls')

class Square:
    def __init__(self, side_length):
        self.side_length = side_length

        def area(self):
            return  self.side_length * self.side_length

            def perimeter(self):
                return self.side_length * 4

            def report(self):
                print ("Side Length : %s" % self.side_length)
                print("Area: %s" % self.area())
                print("Perimeter: %s" % self.perimeter())

                my_square = Square(5)
                my_square.report()