online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
''' Sets and dictionaries demonstration 11/9/2021 -Dr. G ''' #get access to the data structures in the data file import data ''' PART 1 Lists, Tuples, and Sets ''' #You've learned already how to group things together into one variable with a list #Lists are ordered, mutable, and allow duplicates list_things = [1,"apple", "grape", 3.14, True] #You've also seen tuples #Tuples are ordered, immutable, and allow duplicates #list_things = (1,"apple", "grape", 3.14, True) ''' print(type(list_things)) print() print(list_things) print(list_things[0]) print(list_things[1]) print(list_things[2]) print(list_things[3]) print(list_things[4]) print() for i in list_things: print(i) ''' ''' #Sets are unordered, immutable, unindexed, and don't allow duplicates set_things = {1,"apple", "grape", 3.14, 45} #print a set print(set_things) #iterate across a set for i in set_things: print(i) #try to directly access an element #print(set_things[0]) #But, you can also check membership #print("apple" in list_things) #set_things.add("apple") #print(set_things) #Look up the set functions #https://docs.python.org/3/tutorial/datastructures.html#sets #https://www.w3schools.com/python/python_ref_set.asp ''' ''' #Now we will start over with a different set set_food = {"apple", "grape", "squash", "spinach", "banana"} #for i in set_food: print(i) #Add celery and reprint #Create a veggie set with an additional veg #Print out the union and intersection with the food set #Convert the intersection of the two sets into a list #When would sets be appropriate to use? ''' ''' Group practice problem 1 Take the random numbers array use a set to get rid of duplicates and print the difference in the two lengths. Using the sets from data.py print who has had 5001 but still needs to complete 5002 Using the sets from data.py print out people who have had both classes ''' '''PART 2 Dictionaries''' ''' #The right tool for the right job. #There are many other structures available that store things in different ways #A-List or associated arrays is another neat way of storing data dict_things = {"Name" : "Blarg", "HitPoints" : 45, "Strength" : 89} #print(dict_things) #print (dict_things[0]) #Can we change data within a dictionary? #Can we modify a dictionary? #dict_things. ??? ({"Name" : "Bob"}) print(dict_things) #Take a look at the functions for a dict type #add mana and reprint #dict_things. ??? ({"Mana" : 45}) #remove mana and reprint ''' ''' #Iterating through a dictionary: #iterate through the dict #iterate through the dict keys #iterate through the dict values #iterate through the dict using items ''' ''' Group practice problem 2 Notes.txt contains a list of note names and their associated midi numeric codes Use file io to load a dictionary so you can call up a notes code using it's name. That way you can change the numbering system without worrying about changing the name. Starter code provided below. Tip: Don't forget strip... ''' ''' notes = dict() file = open("Notes.txt","r") for line in file: ????? ????? #should print 117 print(notes["A8"]) ''' '''Part 3 : Adding more complexity ''' ''' dict_things = {"Name" : "Blarg", "HitPoints" : 45, "Strength" : 89} #Let's make something a little more complex #make this look better with some new lines #what's this code doing? list_chars = [dict_things, {"Name" : "Gwherig", "HitPoints" : 45, "Strength" : 76}, {"Name" : "Bob", "HitPoints" : 5, "Strength" : 6},{"Name":"Sparhawk", "HitPoints":200, "Strength" : 100}] #access a single "character" #list all character names #make a set with the names of the good guys #make a set with the names of the bad guys #print whether each member is a good or bad guy based on their name '''
random_numbers = [1,4,45,8,7,8,8,9,8,7,5,5,55,456,789,789,45,22] completed_5001 = {"Logain Ablar", "Merana Ambrey", "Naean Arawn", "Rhadam Asunawa", "Aviendha Aiel"} completed_5002 = {"Logain Ablar", "Naean Arawn", "Aviendha Aiel"}
127,G9 126,F#9 126,Gb9 125,F9 124,E9 123,D#9 123,Eb9 122,D9 121,C#9 122,Db9 120,C9 119,B8 118,A#8 118,Bb8 117,A8 116,G#8 116,Ab8 115,G8 114,F#8 115,Gb8 113,F8 112,E8 111,D#8 112,Eb8 110,D8 109,C#8 109,Db8 108,C8 107,B7 106,A#7 106,Bb7 105,A7 104,G#7 104,Ab7 103,G7 102,F#7 102,Gb7 101,F7 100,E7 99,D#7 99,Eb7 98,D7 97,C#7 97,Db7 96,C7 95,B6 94,A#6 94,Bb6 93,A6 92,G#6 92,Ab6 91,G6 90,F#6 90,Gb6 89,F6 88,E6 87,D#6 87,Eb6 86,D6 85,C#6 85,Db6 84,C6 83,B5 82,A#5 82,Bb5 81,A5 80,G#5 80,Ab5 79,G5 78,F#5 78,Gb5 77,F5 76,E5 75,D#5 75,Eb5 74,D5 73,C#5 73,Db5 72,C5 71,B4 70,A#4 70,Bb4 69,A4 68,G#4 68,Ab4 67,G4 66,F#4 66,Gb4 65,F4 64,E4 63,D#4 63,Eb4 62,D4 61,C#4 61,Db4 60,C4 59,B3 58,A#3 58,Bb3 57,A3 56,G#3 56,Ab3 55,G3 54,F#3 54,Gb3 53,F3 52,E3 51,D#3 51,Eb3 50,D3 49,C#3 49,Db3 48,C3 47,B2 46,A#2 46,Bb2 45,A2 44,G#2 44,Ab2 43,G2 42,F#2 42,Gb2 41,F2 40,E2 39,D#2 39,Eb2 38,D2 37,C#2 37,Db2 36,C2 35,B1 34,A#1 34,Bb1 33,A1 32,G#1 32,Ab1 31,G1 30,F#1 30,Gb1 29,F1 28,E1 27,D#1 27,Eb1 26,D1 25,C#1 25,Db1 24,C1 23,B0 22,A#0 22,Bb0 21,A0

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue