Ugrás a fő tartalomra

Python Core tanfolyam

 Python Core tanfolyam project megoldások





# ---------- Exponentiation

print(0.01*(2**30))



# ---------- simple calculator

x = int(input())

y = int(input())

print(x + y)


# ---------- FizzBuzz

n = int(input())

for x in range(1, n):


    if x % 2 == 0 :

        continue


    if x % 3 == 0 and x % 5 == 0:

        print("SoloLearn")

    elif x % 3 == 0:

        print("Solo")

    elif x % 5 == 0:

        print("Learn")


    else:

        print(x)


# ---------- Celsius to Fahrenheit

celsius = int(input())


def conv(c):

    #your code goes here

    return 9/5 * c + 32    


fahrenheit = conv(celsius)

print(fahrenheit)


# ---------- Book Titles

file = open("/usercode/files/books.txt", "r")


lines = file.readlines()

vege = (len(lines))

szamol=1


for line in lines:

    if szamol < vege :

        print(line[0] + str(len(line) -1 ))

    else:

        print(line[0] + str(len(line)))

    szamol += 1


file.close()


# Longest Word

txt = input()


szoveg = txt.split()

leghosszab =''

for teszt in szoveg:    

    if len(leghosszab) < len(teszt) :

        leghosszab = teszt


#print(leghosszab, len(leghosszab))  

print(leghosszab) 


# Fibonacci

num = int(input())


def fibonacci(n):

    n1, n2 = 0, 1

    count = 0


    while count < n:

       print(n1)

       nth = n1 + n2


       n1 = n2

       n2 = nth

       count += 1



fibonacci(num)


# Juice Maker

class Juice:

    def __init__(self, name, capacity):

        self.name = name

        self.capacity = capacity


    def __str__(self):

        return (self.name + ' ('+str(self.capacity)+'L)')


    

    def __add__(self, b): 

        return (self.name + '&' +b.name +' (' + str(self.capacity + b.capacity) + 'L)')


a = Juice('Orange', 1.5)

b = Juice('Apple', 2.0)


result = a + b

print(result)



#  Phone Number Validator

import re

str = input()


pa = r"^[189][0-9]{7}$"

match = re.search(pa, str)

if match:

   print("Valid")

else:

   print("Invalid")


# ---------------- MAP

car = {

    'brand':'BMW',

    'year': 2018,

    'color': 'red',

    'mileage': 15000

}


key =input()


print(car[key])


# ------Accessing Strings

szoveg =input()

figyi = ('a','e', 'i','o','u' )


print(*map(szoveg.lower().count, "aeiou"))


count = 0

for letter in szoveg:

    if letter in figyi:

        count += 1

print(count)

# -----

szoveg='adad ededed'
print(map(szoveg.lower().count, "aeiou"))
print(*map(szoveg.lower().count, "aeiou"))
print(list(map(szoveg.lower().count, "aeiou")))
print(sum(list(map(szoveg.lower().count, "aeiou"))))


# ----  Letter Frequency
szoveg = input()
minta  = input()

elofordulas = szoveg.count(minta)
hossz= len(szoveg)
print(int(elofordulas/hossz*100))

# ----------


from matplotlib import pyplot as plt

import numpy as np

import math

z = ["#f00","#0f0","#00f","#ff0","#f0f","#0ff","#397","#973","#739","#379","#793","#937"]

l = len(z)

a = .75

for i in range(l):

   x = np.arange(0, math.pi*i/a, .005)

   y = np.sin(x*i)

   plt.plot(x, y*i,z[i], label = 'Hullám '+ str(a))

   plt.legend()

   plt.xlabel('angles')

   plt.ylabel('sine')

   plt.title('multiple sine waves')

   plt.savefig('Diagram.png')

   plt.show()

   a += .75  


# ---------- Average Word Length

text = input()

szavak =text.split()

hossz =0

for szo in szavak:

    hossz += len(szo)


print(hossz / len(szavak))


# ----------

def balanced(expression):
    # (()  | ()() | )( | ()) zárójelek kiegyensulyozottságának ellenőrzése
    lista = []
    for egy in expression:
        if egy =='(' :
            lista.insert(0, 5) 
        elif egy ==')' :   
            if len(lista) == 0 :
                return False 
            else :    
                 lista.pop(0)
    if (len(lista) == 0) :
        return True
    else :
        return False 

print(balanced(input()))





Megjegyzések