|
| 1 | +# |
| 2 | +#Variables, integer, float, boolean, string |
| 3 | +student_count = 100 #integer |
| 4 | +rating = 99.2 #float |
| 5 | +is_on = True #boolean True/False (accepted); TRUE/true |
| 6 | +book_name = 'Python Magic' |
| 7 | + |
| 8 | +#Case Sensitive |
| 9 | +# student_count |
| 10 | +# STUDENT_COUNT |
| 11 | +# Student_Count |
| 12 | + |
| 13 | + |
| 14 | +#Strings |
| 15 | +# '', "" ''' ''' |
| 16 | +# string1 = 'Single Quote' |
| 17 | +# string2 = "Double Quote" |
| 18 | +# string3 = ''' |
| 19 | +# Hello, today is 6/28 |
| 20 | + |
| 21 | +# ''' |
| 22 | + |
| 23 | + |
| 24 | +course = 'Python Programming' |
| 25 | +# print(len(course)) #general purpose |
| 26 | +# print(course[0]) |
| 27 | +# print(course[-1]) |
| 28 | + |
| 29 | +#slicing |
| 30 | +# ['beg pos, end pos'] |
| 31 | +# print(course[0:3]) |
| 32 | +# print(course[0:]) |
| 33 | +# print(course[:3]) |
| 34 | +# print(course[:], 'copy of string') |
| 35 | +# print(course[-5:-2]) |
| 36 | +# print(course[0:20:2]) |
| 37 | + |
| 38 | +#string methods |
| 39 | +# course = ' python programming ' |
| 40 | +# print(course.upper(), 'upper case')#converts string to upper case |
| 41 | +# print(course.lower(), 'lower case') #converts string to lower case |
| 42 | +# print(course.title(), 'proper case') #caps 1st letter of every word |
| 43 | +# print(course.strip(), 'strip method') #removes trailing spaces |
| 44 | +# print(course.lstrip(), 'lstrip') #removes trailing left hand space |
| 45 | +# print(course.rstrip(), 'rstrip') #removes trailing right spaces |
| 46 | +# print(course.find('pro')) # returns the index of chars |
| 47 | +# print(course.find('Pro')) #if value not found, return -1 |
| 48 | +# print(course.replace('m', 'M')) #replace m with M |
| 49 | +# print('the'in course) #returns a boolean False |
| 50 | +# print('tho' in course) #returns boolean True |
| 51 | +# print('yellow' not in course) # |
| 52 | + |
| 53 | +#Numbers |
| 54 | +''' |
| 55 | +3 types of numbers in Python. integers, floats, complex |
| 56 | +''' |
| 57 | +# x = 100 # int |
| 58 | +# y = 100.1 #float |
| 59 | +# #c = 100+ 2i |
| 60 | + |
| 61 | +# print(100 + 3) #addition |
| 62 | +# print(100 - 3) #subtraction |
| 63 | +# print(100 * 3) #multiplication |
| 64 | +# print(100/ 3, 'division') #division --> returns float |
| 65 | +# print(100 // 3, 'floor division') #floor --> returns int |
| 66 | +# print(5 % 2, 'modulus') # 5/2 = 2; with 1 remaining |
| 67 | +# print(6 %3, 'modulus, no remainder') |
| 68 | +# print(100 ** 3, 'exponent') #exponent --> left to the power of right. 100 to power of 3 |
| 69 | + |
| 70 | +# y = 100 |
| 71 | +# y = y+3 |
| 72 | +# y +=3 |
| 73 | + |
| 74 | +# import math |
| 75 | +# # print(math.ceil(2.2)) |
| 76 | +# # print(math.floor(2.2)) |
| 77 | + |
| 78 | +# import random |
| 79 | +# print(random.random()) #returns a number between 0 and 1 |
| 80 | +# print(random.randint(0, 10)) #return number between 0 and 10 |
| 81 | + |
| 82 | +# letters = 'abcde' |
| 83 | +# print(random.choice(letters)) |
| 84 | + |
| 85 | +# greeting = 'Hello' |
| 86 | +# user_input = input('Enter your name ') |
| 87 | +# print(greeting + user_input) |
| 88 | + |
| 89 | +# greeting = 2 |
| 90 | +# #user_input = input("Enter your number ") |
| 91 | +# user_input = int(input("Enter your number ")) |
| 92 | +# print(greeting + user_input) |
| 93 | +# print(type(user_input)) |
| 94 | + |
| 95 | + |
| 96 | +# x = input('Enter a number ') |
| 97 | +#convert user input to integer |
| 98 | +# x = int(x) |
| 99 | + |
| 100 | +# #x = -2 |
| 101 | +# if x>0: |
| 102 | +# print('This is a positive number') |
| 103 | +# print("😊") |
| 104 | +# elif x==0: |
| 105 | +# print('The number is 0') |
| 106 | +# else: |
| 107 | +# print('This is a negative number') |
| 108 | + |
| 109 | +# a = 2 |
| 110 | +# b = 40 |
| 111 | +# print(abs(b)) |
| 112 | +# print(min(a, b), 'min num') |
| 113 | +# print(max(a, b), 'max num') |
| 114 | +# print(sum((a, b))) #pass as tuple or list |
| 115 | + |
| 116 | + |
| 117 | +# 0 1 2 3 4 5 |
| 118 | +#animals = ['platypus', 'honeybadger', 'skunk', 'tiger', 'goldfish', 'duck'] |
| 119 | + |
| 120 | +# print(len(animals)) |
| 121 | + |
| 122 | +# for a in animals: |
| 123 | +# print(a) |
| 124 | + |
| 125 | +# numbers = range(5) |
| 126 | +# # print(numbers) |
| 127 | + |
| 128 | +# for n in numbers: |
| 129 | +# print(n) |
| 130 | + |
| 131 | +# for i in range(len(animals)): |
| 132 | +# print(i)#5 --> len(5) |
| 133 | + |
| 134 | +# for i in range(len(animals)): |
| 135 | +# print(animals[i])# |
| 136 | + |
| 137 | +#key/value pairs |
| 138 | +grades = { |
| 139 | + 'A': '90-100', |
| 140 | + 'B': '80-89', |
| 141 | + 'C': '70-79', |
| 142 | + 'D': '60-69', |
| 143 | + 'F' : '0-59' |
| 144 | +} |
| 145 | + |
| 146 | +for key in grades: |
| 147 | + print(grades[key]) |
| 148 | + |
| 149 | + |
| 150 | +for key, value in grades.items(): |
| 151 | + print(key, value) |
0 commit comments