Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Author: Adrian
- Licence: none
- """
- Programmierübung : Python Adder
- S = input()
- for i in range(0, len(S)-1):
- c = S[i:i+1]
- d = i
- if c == "+":
- break
- a = int(S[0:i])+int(S[i+1:len(S)])
- print(a)
- Programmierübung : Substring Counting
- count = 0
- Nadel = str(input())
- Heuhaufen = str(input())
- for i in range(0 , len(Heuhaufen)): #-len(Nadel)):
- Kram = Heuhaufen[i:i+len(Nadel)]
- if Kram == Nadel:
- count = count + 1
- print(count)
- Programmierübung : Watch the Pendulum
- import math
- # import statement goes here
- L = float(input())
- A = float(input())
- # Lösche diesen Kommentar und gib deinen Code hier ein
- for i in range(0,10):
- x = L * math.cos(A * math.cos(i * math.sqrt(9.8/L))) - L * math.cos(A)
- print(x)
- Programmierübung : Centering Text
- x = "Hallo"
- width = int(input())
- while True:
- line = input()
- add = 0
- if line == "END":
- break
- if len (line) > width:
- print("Du schreibst zu viel")
- continue
- if len(line)+width%2 != 0 :
- add = 1
- leftdots = int(((width - len(line)) / 2))*(".")
- rightdots = leftdots
- if len(leftdots)+len(rightdots)+len(line) < width :
- leftdots = leftdots + "."
- print(leftdots + line + rightdots)
- if line == "END":
- break
- # Lösche diesen Kommentar und gib deinen Code hier ein
- #print(width)
- #print(A)
- Programmierübung : Ending Time
- start = input()
- duration = int(input())
- hour = int(start[0:2])
- minutes = int(start[3:5])
- newminutes = minutes + duration
- while newminutes >= 60 :
- newminutes = newminutes - 60
- hour = hour + 1
- while hour >= 24 :
- hour = hour - 24
- if len(str(newminutes)) == 1:
- newminutes = "0" + str(newminutes)
- if len(str(hour)) == 1:
- hour = "0" + str(hour)
- print(str(hour)+":"+str(newminutes))
- Programmierübung : Character Map
- start = 31 #doesn't matter
- end = 31
- while(end < 127):
- start = end + 1
- end = start + 15
- chrZeile = "chr:"
- ordZeile = "asc:"
- for i in range(start, end+1):
- symbolstr = str(chr(i))
- if len(symbolstr) == 1:
- symbolstr = " "+symbolstr+" "
- elif len(symbolstr) == 2:
- symbolstr = " "+symbolstr+" "
- elif len(symbolstr) == 3:
- symbolstr = " "+symbolstr
- chrZeile = chrZeile + symbolstr
- #
- for i in range(start, end+1):
- ordstr = str(i)
- if len(ordstr) == 1:
- ordstr = " "+ordstr+" "
- elif len(ordstr) == 2:
- ordstr = " "+ordstr+" "
- elif len(ordstr) == 3:
- ordstr = " "+ordstr
- ordZeile = ordZeile + ordstr
- print(chrZeile)
- print(ordZeile)
- Programmierübung : Absoluter Wert
- x=int(input())
- y=x
- if x < 0:
- y = (-1)*x
- print(y)
- Programmierübung : First, Second, Third
- x = input()
- x = str(x)
- if x == "1":
- n = x+"st"
- elif x == "2":
- n = x+"nd"
- elif x == "3":
- n = x+"rd"
- else:
- n = x+"th"
- print(n)
- Programmierübung : 26 Letters
- letter = input()
- x = ord(letter)
- if x>=ord("A") and x<=ord("Z"):
- print(x-ord("A")+1)
- else:
- print('invalid')
- Programmierübung : Cubism
- #x = input()
- def cube(n):
- return n*n*n
- #x = input()
- #print(cube(x))
- Programmierübung : Rectangle
- def rectanglePerimeter(width, height):
- return 2*width+2*height
- Programmierübung : Lower-Case Characters
- def lowerChar(char):
- if ord(char) >= 65 and ord(char) <= 90:
- char = chr(ord(char) + 32)
- return char
- Programmierübung : Lower-Case Strings
- def lowerChar(char):
- if ord(char) >= 65 and ord(char) <= 90:
- char = chr(ord(char) + 32)
- return char
- def lowerString(string):
- result = ""
- for i in range(0, len(string)):
- result = result + lowerChar(string[i])
- return result
- Programmierübung : Hypotenuse
- import math
- def hypotenuse(a, b):
- return math.sqrt(a*a+b*b)
- Programmierübung : Die Dreiecke sind rechteckig
- def rightTrianglePerimeter(a, b):
- return a + b + hypotenuse(a, b)
- Programmierübung : 2D Distance
- def distance2D(x1, y1, x2, y2):
- dx = x1-x2
- dy = y1-y2
- return hypotenuse(dx, dy)
- Programmierübung : Secure the Perimeter
- def trianglePerimeter(xA, yA, xB, yB, xC, yC):
- return distance2D(xA, yA, xB, yB) + distance2D(xA, yA, xC, yC) + distance2D(xB, yB, xC, yC)
- Programmierübung : Alphabet Aerobics
- for c in range(0, 26):
- print(chr(ord('A')+c), end = "")
- Programmierübung : Lucky Sevens
- for i in range(17, 98, 10):
- print(i)
- Sortierübung: One None
- «blank line»
- None
- <class 'NoneType'>
- <class 'type'>
- Programmierübung : Monkey in the Middle
- def middle(L): return L[len(L)//2]
- Programmierübung : It's Natural
- def naturalNumbers(n):
- list = []
- for i in range(1, n+1):
- list += [i]
- return list
- #print(naturalNumbers(5))
- Programmierübung : Palindrome
- def isPalindrome(S):
- x = True
- for i in range(len(S)//2):
- if S[i] != S[-i-1]:
- x = False
- return x
- #print(isPalindrome(input()))
- Programmierübung : Product
- def prod(L):
- x = 1
- for i in range(len(L)):
- x *= L[i]
- return x
- Programmierübung : for in
- # Lösche diesen Kommentar und gib deinen Code hier ein
- def prod(L):
- x = 1
- for i in L:
- x *= i
- return x
- Sortierübung: à la Mode
- return i
- for i in L:
- for i in range(0, 10):
- if frequency[i]==max(frequency):
- def mode(L):
- frequency = [0]*10
- frequency[i] = frequency[i] + 1
- Programmierübung : The Replacements
- def replace(list, X, Y):
- while X in list:
- x = list.index(X)
- list.remove(X)
- list.insert(x, Y)
- return list
- Programmierübung : Exact Postage
- def postalValidate(S):
- S = S.replace(" ", "")
- #def false():
- #return False
- def check(S):
- x = []
- y = True
- for i in range(len(S)):
- if i % 2 == 0:
- #print("JHJHGHJHGHJHGHJHGHJHG")
- x.append(S[i].isalpha())
- else:
- #print("123")
- x.append(S[i].isdigit())
- if False in x or len(S)<1 or len(S)%2 != 0:
- y = False
- return y
- if check(S) == True:
- return S.upper()
- else:
- return False
- #print(postalValidate("k 2 A 1a"))
- Programmierübung : Reading the Program
- def getBASIC():
- liste = []
- while True:
- x = input()
- liste.append(x)
- if x.endswith("END"):
- break
- return liste
- Programmierübung : Geh dort hin
- def findLine(prog, target):
- for i in range(len(prog)):
- if prog[i].startswith(target):
- return i
- Programmierübung : Smart Simulation
- # here is a broken solution to get you started
- def execute(prog):
- location = 0
- x = []
- while True:
- if location==len(prog)-1: return "success"
- T = prog[location].split()[-1]
- location = findLine(prog, T)
- if T in x: return "infinite loop"
- x.append(T)
- Programmierübung : BASIC Simulator
- # def getBASIC from subtask 1
- def getBASIC():
- liste = []
- while True:
- x = input()
- liste.append(x)
- if x.endswith("END"):
- break
- return liste
- # def findLine from subtask 2
- def findLine(prog, target):
- for i in range(len(prog)):
- if prog[i].startswith(target):
- return i
- # def execute from subtask 3
- def execute(prog):
- location = 0
- x = []
- while True:
- if location==len(prog)-1: return "success"
- T = prog[location].split()[-1]
- location = findLine(prog, T)
- if T in x: return "infinite loop"
- x.append(T)
- print(execute(getBASIC()))
- Programmierübung : Forty Below In The Winter
- x = input()
- if "C" in x:
- x = float(x.rstrip("C"))
- f = str(x*9/5+32)
- o = f + "F"
- elif "F" in x:
- x = float(x.rstrip("F"))
- c = str((x-32)*5/9)
- o = c + "C"
- print(o)
- Programmierübung : Credit Check
- def check(S):
- if len(S) != 19:
- #print("len")
- return False
- for i in range(19):
- if (i+1) % 5 == 0:
- if S[i] != " ":
- #print("nospaces")
- return False
- else:
- #if S[i].isdigit != True:
- if not 48 <= ord(S[i]) <= 57:
- #print("nodigits")
- #print(S[i])
- #print(ord(S[i]))
- return False
- s = S.replace(" ", "")
- q = 0
- for i in range(len(s)):
- q += int(s[i])
- if q % 10 == 0:
- #print("ok")
- return True
- else:
- #print("notdivisibleby10")
- return False
- Programmierübung : Poetic Analysis
- import operator
- stuff = True
- worddic = {}
- while True:
- x = input().lower()
- x = x.split(" ")
- if "###" in x:
- break
- for i in range(len(x)):
- if x[i] in worddic:
- worddic[x[i]] += 1
- else:
- worddic[x[i]] = 0
- wordlist = list(worddic.keys())
- wordcount = list(worddic.values())
- print(wordlist[wordcount.index(max(wordcount))])
- Programmierübung : Sei Wählerisch
- def choose(n,k):
- answer = 1
- for i in range(k):
- answer *= (n-i)/(k-i)
- return int(answer)
- Programmierübung : Auto-Decryption
- #x = str(input()).upper()
- lg = letterGoodness #[.0817, .0149, .0278, .0425, .1270, .0223, .0202, .0609, .0697, .0015, .0077, .0402, .0241, .0675, .0751, .0193, .0009, .0599, .0633, .0906, .0276, .0098, .0236, .0015, .0197, .0007] #letter goodness
- def Shifter(x, S):
- f = ""
- x = x.upper()
- for i in range(len(x)):
- no = ord(x[i])+S #NewOrdinal
- if no >= ord("Z"): no -= 26
- if no < ord("A"): no += 26 #kein <= sondern < !!
- if x[i] == " ": no = ord(" ")
- f = f + chr(no)
- return f
- def Evaluate(Was):
- Liste = []
- #goodness = 0.0
- for i in range(26):
- Wann = Shifter(Was, i) #Was=Input Wann=geschiftet
- goodness = 0.0
- for n in range(len(Was)):
- Buchstabe = Wann[n]
- if Buchstabe != " ":
- goodness += lg[ord(Wann[n])-ord("A")]
- Liste.append(goodness)
- print(Shifter(Was, Liste.index(max(Liste))))
- eingabe = input()
- Evaluate(eingabe)
- Programmierübung : Blast Up
- def countup(n):
- if n == 1:
- print('Blastoff!')
- else:
- countup(n - 1)
- print(n)
- Programmierübung : Double Time
- def countdownBy2(n):
- if n <= 0:
- print('Blastoff!')
- else:
- print(n)
- countdownBy2(n - 2)
- # delete this comment and enter your code here
- Programmierübung : Quersumme
- def digitalSum(n):
- if n < 10:
- return n
- else:
- return n%10 + digitalSum(n//10)
- Programmierübung : Einstellige Quersumme
- def digitalRoot(n):
- if n <10:
- return n
- else:
- return digitalRoot(digitalSum(n))
- Programmierübung : Collatz-Folge
- def hailstone(n):
- print(int(n))
- if n > 1:
- if n % 2 == 0:
- hailstone(n/2)
- else:
- hailstone(n*3+1)
- Programmierübung : Searching a Nested List
- def nestedListContains(NL, target):
- if isinstance(NL, int):
- if NL == target:
- return True
- else:
- return False
- else:
- contains = False
- for i in range(len(NL)):
- if nestedListContains(NL[i], target) == True:
- contains = True
- return contains
- Sortierübung: Fractal Ruler
- ruler(n - 1)
- def ruler(n):
- ruler(n - 1)
- print(n * '-')
- print('-')
- if n == 1:
- else:
- Sortierübung: Nibofacci
- def Fibonacci(n):
- return Fibonacci(n-1) + Fibonacci(n-2)
- else:
- if (n==1 or n==2):
- return 1
- Sortierübung: Fast Fibonacci
- for i in range(3, n+1):
- def Fibonacci(n):
- sequence.append(sequence[i-1] + sequence[i-2])
- sequence = [0, 1, 1] # Fibonacci(0) is 0, Fibonacci(1) and Fibonacci(2) are 1
- return sequence[n]
- Programmierübung : Primed for Takeoff
- #Hab den Tipp mal gelesen, ist ne coole Herangehensweise, vielleicht klappt das ja, ohne den Wikipedia Artikel
- N = 1000001
- isPrime = []
- highestPrime = 2
- for i in range(N): isPrime.append(True)
- isPrime[0], isPrime[1] = False, False
- while highestPrime != False:
- for i in range(highestPrime , (((N-1)//highestPrime)+1)):#das mit der 1 rauszufinden, hat ne Weile gedauert
- isPrime[highestPrime*i] = False
- try:
- highestPrime = isPrime.index(True, highestPrime+1)
- except ValueError:
- highestPrime = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement