Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################################STRING FUNCTIONS
- #zad 16
- message = input("Podaj wiadomosc: ")
- key = int(input("ile znaków chcesz zamienić(1-26) "))
- secret_message = ""
- for char in message:
- if char.isalpha():
- char_code = ord(char)
- char_code += key
- if char.isupper():
- if char_code > ord('Z'):
- char_code -= 26
- if char_code < ord('A'):
- char_code += 26
- else:
- if char_code > ord('z'):
- char_code -= 26
- if char_code < ord('a'):
- char_code += 26
- secret_message += chr(char_code)
- else:
- secret_message += char
- print("Encrypted : ", secret_message)
- key = -key
- orig_message = ""
- for char in secret_message:
- if char.isalpha():
- char_code = ord(char)
- char_code += key
- if char.isupper():
- if char_code > ord('Z'):
- char_code -= 26
- if char_code < ord('A'):
- char_code += 26
- else:
- if char_code > ord ('z'):
- char_code -= 26
- if char_code < ord('a'):
- char_code += 26
- orig_message += chr(char_code)
- else:
- orig_message += char
- print("Decrypted : ", orig_message)
- #zad 15
- # new_string = input("Podaj stringa: ")
- # new_string = new_string.upper()
- # a_list = new_string.split()
- # for word in a_list:
- # print(word[0], end="")
- # print()
- ####################################################EXCEPTIONS & STRINGS
- #zad 14
- # norm_string = (input("Podaj słowo do zaszyfrowania "))
- #
- # secret_string = ""
- #
- # for char in norm_string:
- # secret_string += str(ord(char) - 23)
- # print("Sekretna wiadomosc: ", secret_string)
- # norm_string = ""
- # for i in range(0, len(secret_string)-1, 2):
- # char_code = secret_string[i] + secret_string[i+1]
- # norm_string += chr(int(char_code)+23)
- # print("oryginalna wiadomosc: ", norm_string)
- #zad 13
- # import random
- #
- # rand_num = random.randrange(10)
- # i = 1
- #
- # while (i != rand_num):
- # i += 1
- # while True:
- # try:
- # number = int(input("Zgadnij liczbe od 1 do 10: "))
- #
- # if number == rand_num:
- # print("Zgadłes")
- # break
- # except ValueError:
- # print("Nie podales liczby")
- #zad 12
- # while True:
- # try:
- # number = int(input("Prosze podaj liczbe: "))
- # break
- # except ValueError:
- # print("Nie podales liczby")
- #
- # except:
- # print("Wystapil nieznany blad")
- #
- # print("Dziekuje za podanie liczny, która wynosi: ", number)
- ##################################################### LOOPS
- #Zad 11
- # tree_height = input ("How tall is the tree ")
- # tree_height = int(tree_height)
- # spaces = tree_height - 1
- # hashes = 1
- # stump_spaces = tree_height -1
- # while tree_height != 0:
- # for i in range(spaces):
- # print(' ', end="")
- # for i in range(hashes):
- # print('#', end="")
- # print()
- # spaces -= 1
- # hashes += 2
- # tree_height -= 1
- # for i in range(stump_spaces):
- # print(' ', end="")
- # print('#')
- #zad 10
- # i = 1
- #
- # while i <= 20:
- # if (i % 2) == 0:
- # i += 1
- # continue
- # if i == 15:
- # break
- #
- # print("Odd : ", i)
- # i += 1
- # #zad 9
- # import random
- # rand_num = random.randrange(100)
- # i = 1
- #
- # while (i !=rand_num):
- # i += 1
- #
- # print("Losowa wartosc to: ", rand_num)
- #zad 8
- # money = input('Ile inwestujesz: ')
- # rate = input('Oprocenotwanie ')
- #
- # money = float(money)
- # rate = float(rate) *.01
- #
- # for i in range(10):
- # money = money + (money * rate)
- # print("Zarobek po 10 latach : {:.2f}".format(money))
- #zad 7
- # your_float = input("podja liczbe zmiennoprzeczinkowa: ")
- # your_float = float(your_float)
- # print("Zaokraglij do 2 liczb po przecinku : {:.2f}".format(your_float))
- #Zad 6
- # for i in range(1, 21):
- #
- # if((i % 2) !=0):
- # print("i = ", i)
- ##################################################### LOOPS
- #zad 5
- # age = eval(input('Podaj wiek '))
- #
- # if age < 5:
- # print('u r too young for school')
- # elif (age == 5):
- # print("Go to kindergarten")
- # elif (age > 5) and (age <= 17):
- # grade = age - 5
- # print('Go to {} grade'.format(grade))
- # else:
- # print("Go to collage")
- #zad 4
- #
- # age = eval(input('Podaj wiek '))
- #
- # if (age>= 1 and age <= 18):
- # print("Important Birthday1")
- # elif (age == 21) or (age == 50):
- # print('Important birthday2')
- # elif not(age<65):
- # print("Important Birthdays3")
- # else:
- # print("Sorry not important")
- #zad3
- # num1, operator, num2 = input('Podaj rownanie ').split()
- #
- # num1 = int(num1)
- # num2 = int(num2)
- #
- # if operator == "+":
- # print("{} + {} = {}".format(num1,num2, num1 + num2))
- # elif operator == "-":
- # print("{} - {} = {}".format(num1, num2, num1 - num2))
- # elif operator == "*":
- # print("{} * {} = {}".format(num1, num2, num1 * num2))
- # elif operator == "/":
- # print("{} / {} = {}".format(num1, num2, num1 / num2))
- # else:
- # print("błędny format podaj +, -, * lub /")
- # zad 2
- # miles = input('Podaj ilesc mil ')
- # miles = int(miles)
- # km = miles * 1.60934
- # print("{} miles equals {} kilometers".format(miles,km))
- # zad1
- #
- # num1, num2 = input('Podaj 2 wartosci ').split()
- #
- # num1 = int(num1)
- # num2 = int(num2)
- #
- # sum = num1 + num2
- #
- # diff = num1 - num2
- #
- # prod = num1 * num2
- #
- # quot = num1 / num2
- #
- # remain = num1 % num2
- #
- # print("{} + {} = {}".format(num1,num2,sum))
- # print("{} - {} = {}".format(num1,num2,diff))
- # print("{} * {} = {}".format(num1,num2,prod))
- # print("{} / {} = {}".format(num1,num2,quot))
- # print("{} % {} = {}".format(num1,num2,remain))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement