# -*- coding: utf-8 -*- """ Created on Thu Nov 5 20:13:43 2020 @author: legen """ from clear_console import cls import numpy as np import matplotlib.pyplot as plt import random cls() # Expressing Conditional Logic As Array Operations x = 5 y = True if x<=5 else False print(y) xarr = np.array([1,2,3,4,5]) yarr = np.array([6,7,8,9,10]) condarr = np.array([True, False, True, True, False]) result = [(x if c else y) for x,y,c in zip(xarr, yarr,condarr)] print(result) #output [1, 7, 3, 4, 10] result = [] # Using for loop
# -*- coding: utf-8 -*- """ Created on Mon Sep 21 20:17:33 2020 @author: legen """ import clear_console as cs cs.cls() #Exercise: # using while loop write a program that # sums positive numbers less than 100 x = 0 #init sum = 0 #init while x < 100: sum = sum + x x = x + 1 print("The sum is=", sum) #reset the variables x = 0 sum = 0 #Sum even numbers only while x < 100: if x%2==0: #remainder == 0? sum = sum + x