Cheat Sheet by juicyy
Cheat Sheet by juicyy
Cheat Sheet by juicyy (Combine to Binaray)user_number = ' ' while user_number != ' 0 ' : user_number = input ("Enter a number to convert to binary") number = int(user_number) binary_string = ' ' while (number > 0): remainder = number%2 binary_string = str(remainder)+ binary_string number = number//2 print ("Binary string is", binary_string) Cheat Sheet by juicyy ( List)fruits = [] #an empty list for number in range(5): user_fruit = input("Please enter a fruit") fruits.append(user_fruit) print ("Size of fruit list is", len(fruits)) fruits.sort() for fruit in fruits: print ("Fruit: ", fruit) Cheat Sheet by juicyy (Example)Print (2) – integer Print (2.5) – floating point Print (“Hello”) – string Print (mystr) – variable Print (mystr,”Hi”,2,1.0) -- commas mystr = “Hi” mystr ← name “Hi” ← value can change print (int(1.5)) → 1 print (int(“2”)) → 2 print (float(1)) → 1.0 anything to a float Modulo/Remainder % print (4%2) → 0 print (30%7) → 2 |
Cheat Sheet by juicyy
Cheat Sheet by juicyy
Cheat Sheet by juicyy ( Naming Convention)Rule for giving name - letter - numbers - underscore _ Valid name - _myStr - my3 - Hello_there Invalid name - 3my=”hi” -- cannot start with number - first name=”hi” - first-name - first+name Cheat Sheet by juicyy (Print Name)name = "tim GIRARD" print (name.upper()) → TIM GIRARD print (name.lower()) → tim girard print (name.capitalize()) → Tim girard print (name.title()) → Tim Girard Cheat Sheet by juicyy ( Circle)""" Python Intro Assignment #2 name student number """ #Ask the user for a radius of a circle user_radius = input("What is a radius of a circle?") #Convert the given radius to a floating point radius = float(user_radius) #Make a variable called pi pi = float(3.1415) #Calculate the area of the circle using exponents area = pi(radius*2) #Display the area of the circle to the user print ("The area of the circle is", area) |
Cheat Sheet by juicyy
Cheat Sheet by juicyy (Reverse)
Cheat Sheet by juicyy ( Countdown)
Cheat Sheet by juicyy ( Line)mystr = "Hello" letter_num = 0 while letter_num < len(mystr): print (mystr[letter_num]) letter_num = letter_num + 1 H e l l o |
Cheatography
https://cheatography.com
Super cool bro! Cheat Sheet by juicyyy
"Come and Say Hi"
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets