Asabeneh / 30-Days-Of-Python

30 days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than100 days, follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
37.27k stars 7.23k forks source link

Online playground #543

Open hatemhosny opened 4 days ago

hatemhosny commented 4 days ago

Great work. Thank you.

I suggest adding links to run code samples in an online playground where users can run the code, edit it, save for later and share with others, etc.

This are some examples:

def generate_full_name (first_name = 'Asabeneh', last_name = 'Yetayeh'): space = ' ' full_name = first_name + space + last_name return full_name

print(generate_full_name()) print(generate_full_name('David','Smith'))

def calculate_age (birth_year,current_year = 2021): age = current_year - birth_year return age; print('Age: ', calculate_age(1821))

def weight_of_object (mass, gravity = 9.81): weight = str(mass * gravity)+ ' N' # the value has to be changed to string first return weight print('Weight of an object in Newtons: ', weight_of_object(100)) # 9.81 - average gravity on Earth's surface print('Weight of an object in Newtons: ', weight_of_object(100, 1.62)) # gravity on the surface of the Moon


- Formatting Date Output Using strftime:
[Run in playground](https://livecodes.io/?x=id/7ue3z2srw8q)
```python
from datetime import datetime
new_year = datetime(2020, 1, 1)
print(new_year)      # 2020-01-01 00:00:00
day = new_year.day
month = new_year.month
year = new_year.year
hour = new_year.hour
minute = new_year.minute
second = new_year.second
print(day, month, year, hour, minute) #1 1 2020 0 0
print(f'{day}/{month}/{year}, {hour}:{minute}')  # 1/1/2020, 0:0

np_normal_dis = np.random.normal(5, 0.5, 1000) # mean, standard deviation, number of samples np_normal_dis

min, max, mean, median, sd

print('min: ', np.min(np_normal_dis)) print('max: ', np.max(np_normal_dis)) print('mean: ', np.mean(np_normal_dis)) print('median: ', np.median(np_normal_dis)) print('mode: ', stats.mode(np_normal_dis)) print('sd: ', np.std(np_normal_dis))


- DataFrames
[Run in playground](https://livecodes.io/?x=id/kqbjgzahnpv)
```python
import pandas as pd
import numpy as np
data = [
    {"Name": "Asabeneh", "Country":"Finland","City":"Helsinki"},
    {"Name": "David", "Country":"UK","City":"London"},
    {"Name": "John", "Country":"Sweden","City":"Stockholm"}]
df = pd.DataFrame(data)
print(df)

If you are interested, I can start a PR to add links for running code snippets in the playground.

This playground is LiveCodes, a feature-rich, open-source, client-side code playground that supports 80+ languages/frameworks. The playground can be shared, exported (e.g. to GitHub gists), deployed (to GitHub Pages) and embedded in web pages using a powerful SDK.

LiveCodes runs completely on the client-side (with no backend). It uses Brython or Pyodide to run Python in the browser.

App: https://livecodes.io/ Docs: https://livecodes.io/docs/ GitHub repo: https://github.com/live-codes/livecodes

Disclosure: I'm the author of LiveCodes.

hatemhosny commented 3 days ago

By the way, LiveCodes also supports JS, TS, React, SQL and many more, in case you want to also use it for 30-Days-Of-JavaScript, 30-Days-Of-React, 30-Days-Of-SQL, 30-Days-Of-HTML, 30DaysOfTypeScript, etc

see all starter templates: https://livecodes.io/?new

Bryan-Giitwa commented 3 days ago

By the way, LiveCodes also supports JS, TS, React, SQL and many more, in case you want to also use it for 30-Days-Of-JavaScript, 30-Days-Of-React, 30-Days-Of-SQL, 30-Days-Of-HTML, 30DaysOfTypeScript, etc

see all starter templates: https://livecodes.io/?new

Good idea, if in need of help just let me know.