-
-
Save adrientetar/7529465 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #1 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| def euclidienne(n, d): | |
| return (n//d, n%d) | |
| print(euclidienne(int(input("Donner n >= 0:")), int(input("Donner d > 0:")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #2 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| def puissance(cur, pow): | |
| res = 1 | |
| for i in range(pow): | |
| res *= cur | |
| return res | |
| print(puissance(int(input("Donner un entier n:")), int(input("Donner la puissance désirée:")))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #3 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| def maxList(array): | |
| res = array[0] | |
| for i in array[1:]: | |
| if i > res: | |
| res = i | |
| return res | |
| def maxList_rec(array): | |
| if len(array) == 1: | |
| return array[0] | |
| res = maxList_rec(array[1:]) | |
| if array[0] > res: | |
| res = array[0] | |
| return res | |
| print(maxList_rec([-150, 5000, 2, 0, -250, 5])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #4 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| def nextSyracuse(syr): | |
| if syr%2 == 0: | |
| return syr/2 | |
| else: | |
| return 3*syr+1 | |
| cur = 2013 | |
| print(cur) | |
| while cur != 1: | |
| cur = nextSyracuse(cur) | |
| print(cur) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #5 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| from math import sqrt | |
| def myFunc(x): | |
| return sqrt(1+x**2) | |
| def moyenneFunc(func, a, b): | |
| res = 0 | |
| for i in range(a, b+1): | |
| res += func(i) | |
| res /= (abs(b-a)+1) | |
| return res | |
| print(moyenneFunc(myFunc, 4, 10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python3 | |
| # | |
| # PCSI, TP d'informatique n°4. #6 | |
| # Copyright (C) 2013, Adrien Tétar. All Rights Reserved. | |
| # | |
| from math import sqrt | |
| def myFunc(x): | |
| return sqrt(1+x**2) | |
| def integrale(func, a, b, e): | |
| rect = (b-a)/e | |
| res = 0 | |
| for i in range (0, e): | |
| res += func(a+rect*i) | |
| return res | |
| print(integrale(myFunc, 4, 10, 200)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment