Python
Aus ProgrammingWiki
Wiki-Quelltext dieser Seite.
<language>Python</language>
Es wird der Python Interpreter Brython verwendet. Es wird eine ganze Reihe von Standard-Modulen mitgeliefert, die per import dynamisch geladen werden können.
<run id="5dc551babe5c1">
import uuid
print(uuid.uuid4())
</run>
<run id="5dc559509f9d7">
import random
print(random.random())
</run>
<div id="jsOutputDiv"></div>
<run id="5e8dff97c3c5e">
jquery = window.jQuery
jquery("#jsOutputDiv").before('<button id="button_1">Click me!</button>')
window.alert("test")
</run>
Beispiel für Input und Output:
<run id="5dc55b74a2c73">
#Average Rainfall
#Start
yr = int(input('Enter how many years was tracked:'))
total = 0
for years in range(yr):
print ('The number of months that was tracked was: {} \n'. format((yr)*12))
for months in range(0,12):
average = int(input('The average amount of rainfall for month {} year {}:'. format(months+1, years + 1)))
print ('The average amount of rainfall for month {} year {} is {}.'. format(months+1, years + 1 , average))
total = total + average
else:
avgMonthly = total/(yr*12)
print ('\n The average monthly rainfall for year {} is {} inches'. format(years + 1, avgMonthly))
print ('\n The total amount of rainfall for year {} is {} inches.'. format(years + 1, total))
#End
</run>