Skip to content

Instantly share code, notes, and snippets.

View AmaurySemery's full-sized avatar
😊

Amaury Semery AmaurySemery

😊
View GitHub Profile
@AmaurySemery
AmaurySemery / Python
Created June 29, 2020 08:45
Exceptions avec while
# year <- saisir une année
# input ...
bonrep = False
while bonrep == False:
year = input("Date ? >")
try:
yearnew=int(year)+10
print(yearnew)
bonrep= True
@AmaurySemery
AmaurySemery / Python
Created June 29, 2020 08:18
Gérer les exceptions (erreurs)
try:
a = 14/0
print(a)
except Exception as error:
# ou : except ZeroDivisionError as error :
# print("Division par 0 !")
print("Aïe :" + str(error))
# ou : print(error)
print("fini !")
@AmaurySemery
AmaurySemery / Python
Created June 28, 2020 17:40
Reproduire le système de dés de R20
import random
def lancerUnDe(n):
d = random.randint(1,n)
return d
def lancerDeDes(nbDes,nbFaces):
listeDesDes = []
for i in range(nbDes):
d = lancerUnDe(nbFaces)
@AmaurySemery
AmaurySemery / Python
Created June 28, 2020 14:21
Convertir chiffre arabe en chiffre romain
dict = {1:'I', 4:'IV', 5:'V', 9:'IX', 10:'X', 40:'XL', 50:'L', 90:'XC', 100:'C', 400:'CD', 500:'D', 900:'CM', 1000:'M'}
def arabe(n):
res = ""
for k, v in reversed(sorted(dict.items())):
while n >= k:
n -= k
res += v
return res
@AmaurySemery
AmaurySemery / Python
Last active June 24, 2020 07:59
Travail 23-06-20 Popschool
import requests
owmapik = "7f9054c4edb12a97316c2da4d6fed6c9"
owm_baseurl = "http://api.openweathermap.org/data/2.5/weather?appid=7f9054c4edb12a97316c2da4d6fed6c9&units=metric"
def get_weather(c):
lat = c["ltt"]
long = c["lng"]
own_url = owm_baseurl + "&lat=" + lat + "&lon=" + long
own_data = requests.get(own_url).json()
@AmaurySemery
AmaurySemery / Python
Created June 24, 2020 07:55
Travail 24-06-20 (cours avec Thomas Hocedez Pop School)
# bibliotheque pour executer des requetes web :
import requests
'''
fichier de configuration (config.py) enregistré à côté de ce fichier. il contient l'API etc.
Plus pratique pour se refiler du code... mais tout le monde doit utiliser la même convention
apikey=''
lang='fr'
name='Thomas HOCEDEZ'
'''
@AmaurySemery
AmaurySemery / Arduino
Created June 9, 2020 12:53
Faire varier la luminosité d'une led => PopSchool
int Shambhala; // le nom du bouton poussoir augmentant la luminosité
int Irkalla; // le nom du bouton poussoir diminuant la luminosité
int Chrysopee; // le nom de la led
byte niveau = 0; // la variable "niveau" de 0 à 255 octets
void setup()
{
Shambhala = 4; // le pin du premier bouton poussoir
Irkalla = 2; // le pin du second bouton poussoir
Chrysopee = 5; // le pin de la led
pinMode(Shambhala, INPUT);
@AmaurySemery
AmaurySemery / Python
Created June 9, 2020 12:49
Fonction pour afficher toutes les dates d'une année => PopSchool
# exo 5 fonction qui affiche toutes les dates d'une année (jj MMM AAAA) ex : 14 JUL 2020
import os
def bissextile(annee):
bissextile = False
if (annee % 400 == 0) or (annee % 4 ==0 and not annee % 100 ==0):
bissextile = True
return bissextile
def nb_jour(annee):
@AmaurySemery
AmaurySemery / Python
Created June 9, 2020 12:48
Fonction pour donner le max entre trois chiffres => PopSchool
# exo 4 fonction pour définir le maximum entre 3 chiffres
x = int(input("Entrez le premier nombre : "))
y = int(input("Entrez le deuxième nombre : "))
z = int(input("Entrez le troisième nombre : "))
def max(x,y,z):
if x>y and z:
return(x)
if y>x and z:
return(y)
@AmaurySemery
AmaurySemery / Python
Created June 9, 2020 12:47
Fonction de calcul de l'aire d'un cercle => PopSchool
# exo 3 fonction de calcul de l'aire d'un cercle
rayon = int(input("Entrez le rayon du cercle : "))
from math import*
def aire(rayon):
A=pi*rayon**2
return(A)
print("L'aire du cercle vaut : ", aire(rayon))