Welcome, Guest. Please Login
NTCS Homework Board
  Should discrepancies arise between this website and what is told in class, the information given in class takes priority
  HomeHelpSearchLogin Teacher Calendar Activities Calendar  
 
 
Page Index Toggle Pages: 1
Send Topic Print
December Work (Read 155 times)
Reply #1 - Dec 13th, 2018 at 10:11am

Mr. Vant Erve   Offline
YaBB Teacher
TechCommittee

Posts: 1092
 
Here is the code to solve the NextLetter program you're asked to do part way through CS Circles Lesson 7B.  Copy and paste it if you want!  Change commented lines into code by deleting the hash tag.

#-------------------------------------------------------------
#METHOD 1 is what I would expect you to do

#STEP 1: take input character and store as variable
upperChar = input()

#STEP 2: print the next character in the alphabet

#STEP 2a: Check to see if input is Z and wrap back to A
if upperChar == "Z": print("A")
#OR this way
#if ord(upperChar) == 90: print("A")

#Step 2b: Check to see if input is not Z and print next char
if upperChar != "Z": print( chr( ord(upperChar)+1 ) )

#-------------------------------------------------------------
#METHOD 2 is really cool but uses some math operators you haven't seen yet
#AND IT ONLY TAKES ONE LINE OF CODE!!!
#print( chr( 65 + ( ( ord( input() ) +1 ) - 65 ) % 26 ) )
 

<>< <>< <>< <>< <>< <>< <>< <>< <><
                 Mr. D. Vant Erve

         "I sing, for I cannot be silent;
      His love is the theme of my song"
                 -Fanny J. Crosby
IP Logged
 
Dec 3rd, 2018 at 11:12am

Mr. Vant Erve   Offline
YaBB Teacher
TechCommittee

Posts: 1092
 
Here's the little lesson-ish thing we did today on numbering systems.  This is material you will NOT be responsible for on the exam, but very useful to know!
 

<>< <>< <>< <>< <>< <>< <>< <>< <><
                 Mr. D. Vant Erve

         "I sing, for I cannot be silent;
      His love is the theme of my song"
                 -Fanny J. Crosby
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print