My First Python Program

by levans, Jan 16, 2022, 9:50 PM

We have something of an oddity at AoPS. Our programming classes are in Python but we don't actually use Python. Instead we primarily use PHP and Node.JS for our back end programming. Because of this, I'm pretty proficient at those languages, but not many others. I used to be really good at Java and C/C++, but it's been so long that I've used them that it would take me a bit to get back up to speed on them, C/C++ especially. That being said, I wrote my first Python program on Friday! (Edit: Wow, I need to do some CSS adjustment! to make this look better.)

  1. from collections import defaultdict
  2.  
  3. # Function to return a default
  4. # values for keys that are not present
  5. def def_value():
  6. return "Default"
  7.  
  8. # Defining the dict
  9. d = defaultdict(def_value)
  10. d["a"] = 1
  11. d["b"] = 2
  12.  
  13. print(d["a"])
  14. print(d["b"])
  15. print(d["c"])
This post has been edited 3 times. Last edited by levans, Feb 11, 2022, 6:43 AM

Comment

2 Comments

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Cool, you should re learn java it's fun

by Ladka13, Feb 5, 2022, 6:52 PM

The post below has been deleted. Click to close.
This post has been deleted. Click here to see post.
Yea so since python isn't exactly designed to run in the browser so I think aops uses skulpt for translating python to js calls, there are some terribly slow ways to actually run python in the browser. One is to emulate a full linux machine like on https://copy.sh/v86. Another way which may or may not be faster is to just implement linux syscalls like in https://webvm.io/ , or since the use case is narrowed down just to python you could just use a webassembly version of python like this one that comes up from google https://github.com/pyodide/pyodide, of course the current method is just a ton faster.
The one thing I miss from "real python" at the moment is the giant standard library or "batteries included" that python has but I'm guessing that support for these mostly depends on the upstream open-source project.

by fath2012, Feb 12, 2022, 8:28 PM

Opinions expressed herein are my own and not necessarily those of AoPS Incorporated.

avatar

levans
Archives
- January 2025
+ September 2023
+ September 2022
+ August 2020
+ November 2019
+ March 2019
+ January 2019
+ December 2018
+ September 2016
+ August 2015
+ July 2015
+ April 2015
+ February 2015
+ October 2014
+ August 2014
+ March 2014
+ February 2014
+ October 2013
+ September 2013
+ August 2013
CoC
+ June 2013
+ April 2013
+ February 2013
+ November 2012
+ September 2012
+ August 2012
+ April 2012
+ February 2012
+ January 2012
+ November 2011
Shouts
Submit
  • beautiful css omg

    by yaxuan, Feb 10, 2025, 5:31 AM

  • hello I just saw this

    the CSS here is pro
    $\text{also what is this font}$

    by Yrock, Feb 4, 2025, 2:36 AM

  • hiii it's been a long time

    300th shout!! :D

    by evt917, Dec 20, 2024, 5:15 PM

  • @LostInBali, it's totally based on terminals.

    by levans, May 22, 2024, 12:09 AM

  • HIIII! This is beautiful CSS and it reminds me of bash!!!!!!!
    (I do hope you like terminals)

    by LostInBali, May 1, 2024, 8:41 AM

  • COOOOL BLOG!!

    by Yummo, Feb 4, 2024, 7:09 PM

  • geez 100k+ views

    by ujulee, Dec 5, 2023, 5:47 PM

  • HOW SO ORZ WHAT THE HECK

    by madeleinelee, Dec 5, 2023, 6:03 AM

  • hi $          $

    by Bob_Smart, Nov 4, 2023, 4:38 AM

  • I like this blog so much it's so impressive!

    by BabaLama, May 2, 2023, 1:26 AM

  • bump$    $

    by TethysTide, Nov 16, 2022, 4:18 PM

  • pls don't click my username thanks :)

    by RyanWang, Sep 28, 2022, 4:26 AM

  • aops* $     $

    by programmeruser, Sep 27, 2022, 9:51 PM

  • Hello!$    $

    by Peregrine11, Aug 29, 2022, 9:02 PM

  • this is the best blog on aopa

    by programmeruser, Jun 16, 2022, 12:10 AM

302 shouts
About Owner
  • Posts: 5190
  • Joined: Apr 27, 2007
Blog Stats
  • Blog created: Jul 27, 2011
  • Total entries: 105
  • Total visits: 107948
  • Total comments: 616
Search Blog
a