DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. One in a Million: Teaching Coding With Python

One in a Million: Teaching Coding With Python

A developer and software engineering teaching discusses how he teaches code, showing an example of this with some basic Python.

Shay Tavor user avatar by
Shay Tavor
·
Nov. 06, 18 · Opinion
Like (2)
Save
Tweet
Share
7.25K Views

Join the DZone community and get the full member experience.

Join For Free

I’ve been teaching programming for more than 17 years. During this period, I’ve developed a nice inventory of exercises and code examples. Some of which are old as my teaching career, and even though I’ve taught, and continue to teach, a variety of languages, well, most examples are as good in any language.

Here is one of them — I use it in the first lesson on conditionals. This program generates a random number in the range of [0, 100] and then asks the user to guess it. The user gets one chance — it’s a very early lesson and the students don’t know loops yet. The program outputs “Correct” or “Wrong” and that’s it. Look at it (this time in Python, because that’s the language I teach now):

import random

compNum = (int)(random.random() * 101)

userGuess = (int)(input(“Enter your guess:”))

if compNum == userInput:
	print(“Correct”)
else:
	print(“Wrong”)

Yeah, it’s simple, but yet pretty powerful example. When I show it I type it during the class and then ask the students to try and guess. I know it sounds silly and with no avail, but believe me, it’s such fun!

No one ever manages to guess correctly.

Today, I’ve shown this example again, and, as usual, invited the students to try their luck. One of them yelled from her sit “31.”

“Very well,” I said, “31 for the lady.” And typed in 31.

I pressed enter.

And boom.

I saw “Correct” on the screen.

It was so surprising that I couldn’t talk for a second because it was the first time in 17 years that it ahd happened.

I think now I know the meaning of the phrase “One in a million”! 

P.S.Yeah, I know there are better ways to generate random numbers, I deliberately use this one because it shows a really important principle in software engineering.

Python (language) Coding (social sciences)

Published at DZone with permission of Shay Tavor. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • An Introduction to Data Mesh
  • The 12 Biggest Android App Development Trends in 2023
  • Asynchronous HTTP Requests With RxJava
  • Hidden Classes in Java 15

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: