Question
note: I’m trying to do this in 3 separate defined functions. My main area of confusion is (C)
Asking for help on a python project: I have two constraints, one being a list ALLOWEDINT of [1,2,3,4] and one being ALLOWEDLE
0 0
Add a comment Improve this question Transcribed image text
Answer #1

# do comment if any problem arises

# Code

#global contraints

ALLOWEDINT = [1, 2, 3, 4]

ALLOWEDLENGTH = 4


# a)

# this function returns true if input is not in list

def check_Int(integers):

    for integer in integers:

        if int(integer) not in ALLOWEDINT:

            return True

    return False


# b)

# this function returns true if

def check_Length(integers):

    if len(integers) != 4:

        return True

    return False


# c)

def get_input():

    integers=input('Enter a string: ')

    while check_Int(integers) or check_Length(integers):

        integers=input('Invalid input! Re-Enter a string: ')

    return integers

user_input=get_input()

print(f'You entered {user_input}')

Screenshot of code:

#global contraints 3 [1, 2, 3, 4] 4 ALLOWEDINT 5 ALLOWEDLENGTH 4 6 7 # a) # this function returns true if input is not in lis

Output:

Enter a string: 14 Invalid input! Re-Enter a string: 65 Invalid input! Re-Enter a string: 1234 You entered 1234

Add a comment
Know the answer?
Add Answer to:
note: I’m trying to do this in 3 separate defined functions. My main area of confusion...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries...

    Need help writing these functions in Python: FUNCTION 1 get_course_ids: Consumes a list of Course dictionaries and returns a list of integers representing course IDs. Here's what I have so far but I'm getting a Type Error - list indices must be integers or slices, not dict. def get_course_ids(courses): course_ids = [] for course in courses: course_ids.extend(courses[course])    return course_ids FUNCTION 2 choose_course: Consumes a list of integers representing course IDs and prompts the user to enter a valid ID,...

  • Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions...

    Using Python 3+ for Question P5.9 Instructions: Use one main() to call each of the functions you created. Only use one value of r and h for all the function. Ask the user for the r and h in the main() as an input, and h for all the functions. You should put the functions for areas in a separate file. ​ For example, firstDigtec7ze Write a function e digits n) (returning the number of digits in the argument returning...

  • Write the following functions, as defined by the given IPO comments. Remember to include the IPO...

    Write the following functions, as defined by the given IPO comments. Remember to include the IPO comments in your submission. Be sure to test your code -- you can use the examples given for each function, but you should probably test additional examples as well -- and then comment-out or remove your testing code from your submission!. We will be testing your functions using a separate program, and if your own testing code runs when we load your file it...

  • USING PYTHON 3. For this question, you will build three helper functions and one main function....

    USING PYTHON 3. For this question, you will build three helper functions and one main function. All four functions must work together to draw the letter ‘H. Every line of code written should be inside of a function. Here are the function specifications: 1) Helper function (given): def draw_edges(symbol, width): print(symbol + " "*(width-2) + symbol) 2) Helper function: draw_H(symbol, width, height): This function will draw an "H" symbol, given the symbol, width, and height. This function must call the...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He...

    A)) (Ransom Note Problem) in python A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words. Here is how your program should work to simulate the ransom...

  • Hi. Please help me solve this in python using only while loops, if statements. Can't use...

    Hi. Please help me solve this in python using only while loops, if statements. Can't use for loops and lists. In this programming assignment, you will be writing a program that prints out several shapes via text. In this PA, you will be required to use functions and parameters. This is both to reduce redundancy and to make your code clean and well-structured. Name your program shaper.py Your program should have the capability to print out three different shapes: An...

  • It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #inclu...

    It is a C++ program by using inheritance and vectors My professor said that all the files should be separate. like File.cpp, File.h, Text.cpp,Text.h,Main.cpp I already have these files File.cpp #include "File.h" // Constructor of File that takes File name and type as arguments File::File(string type, string name) {    this->type = type;    this->name = name; } //returns the type. string File::getType() {    return type; } //returns the name of file. string File::getName() {    return name; } File.h #ifndef __FILE_H__ #define...

  • CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1...

    CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Utilizing Lab 2.2 code Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds.There are 2.2 pounds in one kilogram. Create an...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT