Today, let's export 1~100 Some mathematical information between .
We don't need any third-party library this time .
output 1~100 Sum of all numbers
sumNumber = 0 for i in range(1,101): sumNumber += i print('1~100 The sum of all the numbers between is :',
sumNumber)
Or use sum Calculation and method :
print('1~100 The sum of all the numbers between is :',sum(range(1,101)))
output 1~100 All odd numbers between
numbers = [] for i in range(1,101): if (i % 2) == 1: numbers.append(i) print(
numbers)
output 1~100 All even numbers between
numbers = [] for i in range(1,101): if (i % 2) == 0: numbers.append(i) print(
numbers)
output 1~100 The sum of all odd numbers between
numberSum = 0 for i in range(1,101): if (i % 2) == 1: numberSum += i print(
numberSum)
output 1~100 The sum of all even numbers between
numberSum = 0 for i in range(1,101): if (i % 2) == 0: numberSum += i print(
numberSum)
output 1~100 All prime numbers between
def prime(maxNumber): numbers = [] min = 2 while min <= maxNumber: is_prime =
True for i in range(2,min): if (min % i) == 0: is_prime = False break if
is_prime== True: numbers.append(min) min += 1 print('{0} The following prime numbers are :'.format(
maxNumber)) print(numbers) print() # call prime(100)
output 1~100 Sum of all prime numbers between
# coding : utf-8 def prime(maxNumber): numbers = [] min = 2 numberSum = 0 while
min <= maxNumber: is_prime = True for i in range(2,min): if (min % i) == 0:
is_prime= False break if is_prime == True: numbers.append(min) min += 1 for i in
numbers: numberSum += i print('%s The sum of prime numbers within is :%s' % (maxNumber,numberSum)) prime(100
)
output 1~100 All composite numbers
maxNumber = 100 numbers = [] min = 2 numberSum = 0 for i in range(1,101):
numbers.append(i) while min <= maxNumber: is_prime = True for i in range(2,min):
if (min % i) == 0: is_prime = False break if is_prime == True: numbers.remove(
min) min += 1 print(numbers)
output 1~100 Sum of all composite numbers
maxNumber = 100 numbers = [] min = 2 numberSum = 0 for i in range(1,101):
numbers.append(i) while min <= maxNumber: is_prime = True for i in range(2,min):
if (min % i) == 0: is_prime = False break if is_prime == True: numbers.remove(
min) min += 1 for i in numbers: numberSum += i print('%s The sum of composite numbers within is :%s' % (maxNumber
,numberSum))
output 1~100 All numbers
for i in range(1,101): print(i,end = ' ')
Output pi
from math import pi print(' PI :',pi)
Output natural constant
from math import e print(' Natural constant :',e)
Technology