-1

Im able too generate a number properly how I want but I want too make a custom input so the user can generate an exact amount of numbers not just a set amount of numbers.

if menu == "1":
    code = input("")
    if code == "":
        countrycode = input("Please Enter Country Code: ")
        areacode = input("Enter area Code: ")
        city = (random.randint(200,999))    
        last = (random.randint(1000,9999))
        number = ("+"+countrycode+areacode+str(city)+str(last))

        
        print(number)

2 Answers2

0

To do this, you can use a while True loop that takes in input every single time they want to input a phone number. If they input something that you don't want, break out of the while True loop. Otherwise, you take in the phone number. To hold the set of numbers, just add them to arrays.

Edited off your code:

if menu == "1":
while(True):
    code = input("")
    if code == "":
        countrycode = input("Please Enter Country Code: ")
        areacode = input("Enter area Code: ")
        city = (random.randint(200,999))    
        last = (random.randint(1000,9999))
        number = ("+"+countrycode+areacode+str(city)+str(last))

    
        print(number)
    else:
        break
    
        
        
-1

I'm not sure I fully understand your question, but i'll give it a shot:

import random


class Data():
    def __init__(self) -> None:
        country_code = ""
        area_code = ""
        city = ""
        last = ""
        
    def __str__(self):
        return f"+{self.country_code}-{self.area_code}-{self.city}-{self.last}"

def main():
    number_of_entries = int(input("How Many Entries: "))
    
    list_of_information = []
    for _ in range(0, number_of_entries):
        new_data = Data()
        new_data.country_code = input("Please Enter Country Code: ")
        new_data.area_code = input("Enter area Code: ")
        new_data.city = str(random.randint(200,999))  
        new_data.last = str(random.randint(1000,9999))
        list_of_information.append(new_data)
    
    for entry in list_of_information:
        print(entry)

if __name__ == '__main__':
    main()

Sample:

How Many Entries: 2
Please Enter Country Code: 1
Enter area Code: 604
Please Enter Country Code: 1
Enter area Code: 30
+1-604-394-5276
+1-30-840-8783
Dylan
  • 26
  • 5