×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: ulkir
Added: Apr 30, 2020 3:44 PM
Views: 4315
  1. #Basic Arithmatic
  2. #01-Numbers
  3.  
  4. #Addition
  5. print('Addition: ', 7+4)
  6. #Subtraction
  7. print('Subtraction: ', 7-4)
  8. #Multiplication
  9. print('Multiplication: ', 7*4)
  10. #Divison
  11. print('Division: ', 7/4)
  12. #Floor Division
  13. print('Floor Division: ', 7//4)
  14. #Modulo
  15. print('Modulo: ', 7%4)
  16.  
  17. #Variable Assignments
  18. a = 5
  19. print(a+a)
  20. a = 10
  21. a = a + a
  22. print(a)
  23.  
  24. #powers
  25. print(2**3) # 2* 2* 2= 8
  26.  
  27. # can also do roots this way
  28. print(4**0.5)
  29.  
  30. #Example
  31. my_income = 100
  32. tax_rate = 0.2
  33. my_taxes = my_income*tax_rate
  34. print(my_taxes)
  35.  
  36.  
  37. #02_VariablesAssignments
  38.  
  39. my_dogs = 2
  40. print(my_dogs)
  41.  
  42. my_dogs = ['Samy', 'Frankie']
  43. print(my_dogs)
  44.  
  45. #Reassingning variables
  46.  
  47. #a = a + 10
  48. #print(a)
  49.  
  50. #a += 10
  51. #print(a)
  52.  
  53. a *= 2
  54. print(a)
  55.  
  56. #to learn what kind of data you are using
  57. type(a)
  58. print(type(a))
  59.  
  60.  
  61.  
  62. #03-Strings
  63. #Define string variable
  64. name = "ilhan"
  65. print(name)
  66. print(type(name))
  67. #We can use this to print a string backwards - reverse string
  68. print(s[::-1])
  69.  
  70. #Concatenate
  71.  
  72. b = 'hello world'
  73.  
  74. b = b + ' concatenate me!'
  75. print(b)
  76.  
  77. print('Addition: ', (2+1))
  78.  
  79. letter = 'z'
  80. print(letter*10)
  81.  
  82. #Uppercase
  83.  
  84. m = 'my name is Ilhan'
  85. print(m.upper())
  86.  
  87. #lowercase
  88. print(m.lower())
  89.  
  90. #Split- split a string by blank space
  91. print(m.split())
  92.  
  93.  
  94.  
  95. #Format conversion methods
  96.  
  97. print('He said his name was %s'%'Frank')
  98. print('He said his name was %r'%'Frank')
  99.  
  100. # \t
  101. print('I once caught a fish %s'% 'this \tbig')
  102. print('I once caught a fish %r'% 'this \tbig')
  103.  
  104. # %s and %d
  105. print('I wrote %s programs today'%3.75)
  106. print('I wrote %d programs today'%3.75)
  107.  
  108. #Padding and precision of floating point numbers
  109. print('Floating point numbers: %5.2f'%(13.144))
  110. print('Floating point numbers: %5.0f'%(13.144))
  111.  
  112.  
  113.  
  114. # .format()
  115.  
  116. print('Insert another string with curly brackets: {}'.format('The inserted string'))
  117. print('My First name is ilhan and last name is: {}'.format('turkmen'))
  118.  
  119.  
  120.  
  121.