Posts

3 Methods of Reversing a User Input List in Python

  # defining empty list uList = [] # defining the number of elements in the list nList = int(input("List of how many elements? ")) print("Now enter the elements of your list one by one.") # taking elements of the list as user input for i in range(0,nList): element = int(input()) uList.append(element) print(f"The original list is {uList}") # taking copy of the list, storing it in variable, then reversing it reverse1 = uList[:] reverse1.reverse() print(f"The first reverse of the original list {uList} is {reverse1}") reverse2 = uList[::-1] print(f"The second reverse of the original list {uList} is {reverse2}") reverse3 = uList[:] for i in range(len(reverse3)//2): reverse3[i], reverse3[len(reverse3)-i-1] = reverse3[len(reverse3)-i-1], reverse3[i] print(f"The third reverse of the original list {uList} is {reverse3}") if reverse1 == reverse2 and reverse2 == reverse3: print("All the three meth

Reverse a string in Python

A method to reverse a string; stri = "abdur" revStr = stri[::-1] print(revStr)

Function in Python that Reverse a given List

 The following function in python will return the reverse of the given list. def reverseList(n): reverseL = uList[:] for i in range(len(reverseL)//2): reverseL[i], reverseL[len(reverseL)-i-1] = reverseL[len(reverseL)-i-1], reverseL[i] print(f"The reverse of the original list {uList} is {reverseL}") uList = [45,66,7,1,333] reverseList(uList)

Taking List as user input in Python

The following is one of the ways to take 'list' as user input. # defining empty list uList = [] # defining the number of elements in the list nList = int(input("List of how many elements? ")) print("Now enter the elements of your list one by one.") # taking elements of the list as user input for i in range(0,nList): element = int(input()) uList.append(element) print(f"The original list is {uList}")

A range of numbers whether they are fully divisible or not

     In this program, we are asking about  'how many apples are available to be distributed amongst a range of boys?' The program is meant to return what number of boys in the range of numbers will equally receive all the available apples. apples = int(input("How many apples are there: ")) minBoys = int(input("The minimum num of boys are: ")) maxBoys = int(input("The maximum num of boys are: ")) print(f"There are {apples} apples, they are to be divided amongst {minBoys} to {maxBoys} boys.") for i in range(minBoys, maxBoys+1): if apples%i==0: print(f"The {apples} apples can be equally divided among the {i} boys.") else: print(f"The {apples} apples cannot be equally divided among the {i} boys.")

Calculate user age and when will they turn 100

The following Python program calculates 2 things; 1. when will the user turn 100 2. what will be the user's age in a certain year  # when will I be 100 years old age_yob = input("Plz enter your age or year of birth: ") # my age in the future year age_in_year = input("You age in a certain year: ") current_year = 2022 # age_in_year = float(age_in_year) # dealing age try: if len(age_yob) < 4: if len(age_yob) == 3: print("You are already 100 years old.") elif len(age_yob) < 3: age_100 = 100 - float(age_yob) print(f"You will turn 100 in {current_year + age_100}") add_to_age = float(age_in_year) - current_year age_asked = float(age_yob) + add_to_age print(f"You age in {age_in_year} will be {age_asked}") else: # dealing yob age_100 = float(age_yob) + 100 print(f"You will turn 100

Extract Emails from a rough string using Regular Expressions

import re str = """A Better Fake Name Generator FAKE NAME MORE TOOLS ABOUT CONTACT US Tools: IDENTITY GENERATOR RANDOM TEXT FAKE EMAIL FAKE CREDIT CARD GENERATOR FAKE CREDIT CARD VALIDATOR FAKE DRIVER'S LICENSE FAKE COMPANY FAKE PHONE NUMBER FAKE SOCIAL SECURITY NUMBER VIEW ALL TOOLS » More: ABOUT CONTACT US HOME TOOLS FAKE EMAIL GENERATOR ×FauxID.com is a free service and we rely on ad revenue. Please consider disabling your ad blocker on this site. Create List of Fake Emails Free Email List Generator Simple Fake Email List Generator. Select how many email addresses you are looking for and click "generate". Number of Email to Generate 10 Number between 1-1000 fiona.krajcik@padberg.biz bberge@gmail.com kaden.brown@schmidt.com lschinner@hotmail.com naomi.stamm@hotmail.com klein.katrina@larson.net qbailey@robel.com lina.hessel@bosco.com dfranecki@strosin.biz juanita.becker@schuster.com Fake Identity • Fake Name • Fake SSN • Fake Address • F