Example #1
0
from utility import multiply, divide
from shopping.more_shopping import shopping_cart
import random
print(random)

print(shopping_cart.buy('apple'))
print(divide(4, 3))
print(multiply(5, 4))
print(max([1, 2, 3]))

if __name__ == '__main__':
    print('please run this')
Example #2
0
from utility import multiply, divide, max
from shopping.more_shopping.shopping_cart import buy
import random
import sys

if __name__ == '__main__':  # executes if this file is being run
    print(multiply(2, 3))  # => 6
    print(divide(2, 3))  # => 0.666666666666666
    print(buy('apple'))  # ['apple']
    print(max())  # oops
    print(__name__)  # __main__

print(random)  # <module'random' from 'C:\\Users\\alexc\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\random.py'>
help(random)  # gives helpful information about the random package
print(dir(random))  # lists every method you can use within the random package
print(random.random())  # gives a random number between 0 and 1
print(random.randint(1, 10))  # gives a random integer inclusively between two parameters
print(random.choice([1, 2, 3, 4, 5]))  # picks a random value within the array

my_list = [1, 2, 3, 4, 5]
random.shuffle(my_list)
print(my_list)  # shuffled list

print(sys)  # <module 'sys' (built-in)>
sys.argv  # runs files from the terminal


Example #3
0
import utility
#another way to import modules

from utility import multiply, divide  #( we can anso use * to import all modules at a  time)

import shopping.more_shopping.shopping_cart
# another way to import packages

from shopping.more_shopping import shopping_cart

print(utility.multiply(3, 4))
print(utility.divide(4, 2))

print(utility.multiply(5, 10))
print(utility.divide(25, 5))

print(shopping.more_shopping.shopping_cart.buy('apple'))

print(shopping_cart.buy('orange'))

if __name__ == '__main__':
    print('please run this')
from modules import utility
import shopping.shopping_cart
# import shopping.more_shopping.shopping_cart
from shopping.more_shopping.shopping_cart import buy
import random
import sys

my_list = [1, 2, 3, 4, 5]

print(utility)
print(shopping.shopping_cart.buy('apple'))
print(buy('banana'))
# prints a random number between 0 and 1
print(random.random())

# prints a random number between the specified intergers
print(random.randint(2, 10))
print(random.randrange(0,20,1))
print(random.choice((1,2,3,4,5)))

random.shuffle(my_list)
print(my_list, '\n')

print(sys, '\n')

Example #5
0
# Main Module

from utility import multiply, divide
# This can become cumbersome
# import shopping.more_shopping.shopping_cart
# Use this
# from shopping.more_shopping.shopping_cart import buy
# Or import the entire module!
from shopping.more_shopping import shopping_cart

print(multiply(5,4))

print(shopping_cart.buy('bike'))

print(divide(5,2))

print(__name__)

if __name__ == '__main__':
    print('please run this')
# import shopping.more_shopping.shopping_cart # import module directly from package
from shopping.more_shopping import shopping_cart as whatsGood
import random as oulala
import sys
import pyjokes

# from random import shuffle as oulala

# print(utility)
# print(shopping.more_shopping.shopping_cart)

if __name__ == "__main__":
    print(multiply(2, 23))
    print(divide(23, 2))

    print(whatsGood.buy("apple"))

    print(max([1, 2, 3, 4, 5, 232, 23, 4, 4]))

    # __main__ is always given to the file that is the root of code execution
    print(__name__)
    if __name__ == "__main__":
        print("please run this print statement")

# python built-in modules
# they come with python, when downloading the python interpreter
# https://docs.python.org/3/py-modindex.html

# print(random)
# help(random)
# print(dir(random))
Example #7
0
from utility import *
from shopping.more_shopping.shopping_cart import buy

# __name__ == __main__ is file from which we call other files (or file we run)
if __name__ == '__main__':
    print("Please run this")
print(__name__)
print(divide(10, 5))
print(buy)
print(buy('apple'))
print(multiply(3, 4))


class Student():
    pass


st1 = Student()

print(type(st1))

print(type(stu1))
Example #8
0
# import shopping.shopping_cart
# import shopping.more_shopping.shopping_cart
from shopping.more_shopping import shopping_cart
from utility import divide

product = shopping_cart.buy("apple")

print("product:", product)
print("divide(6, 3):", divide(6, 3))  # 2

if __name__ == "__main__":
    print("max[1, 2, 3]:", max([1, 2, 3]))  # 3
Example #9
0
from random import randint

from utilities.utils import multiply, divide
from shopping.more_shopping import shopping_cart

print(f'Shopping name: { __name__ }')

if __name__ != '__main__':
    print('I am not in main!')
    exit()

print('I am in main! \n')

cart = shopping_cart.buy('apple')
print(f'Cart: { cart }')

print(f'Multiply: { multiply(3, 2) }')
print(f'Divide: { divide(3, 2) }')
print(f'Random: { randint(0, 1) }')