Answer:
The solution code is written in Python 3:
- def modifyList(listNumber):
- posCount = 0
- negCount = 0
-
- for x in listNumber:
- if x > 0:
- posCount += 1
- else:
- negCount += 1
-
- if(posCount == len(listNumber)):
- listNumber.append(max(listNumber))
-
- if(negCount == len(listNumber)):
- listNumber.append(min(listNumber))
-
- print(listNumber)
-
- modifyList([-1,-99,-81])
- modifyList([1,99,8])
- modifyList([-1,99,-81])
Explanation:
The key step to solve this problem is to define two variables, posCount and negCount, to track the number of positive value and negative value from the input list (Line 2 - 3).
To track the posCount and negCount, we can traverse through the for-loop and create if else statement to check if the current number x is bigger than 0 then increment posCount by 1 otherwise increment negCount (Line 5- 9).
If all number in the list are positive, the posCount should be equal to the length of the input list and the same rule is applied to negCount. If one of them happens, the listNumber will append either the maximum number (Line 11 -12) or append the minimum number (Line 14-15).
If both posCount and negCount are not equal to the list length, the block of code Line 11 -15 will be skipped.
At last we can print the listNumber (Line 17).
If we test our function using the three sets of input list, we shall get the following results:
[-1, -99, -81, -99]
[1, 99, 8, 99]
[-1, 99, -81]
Answer:
movieCost=4.95
Float
movieStars = ['Carrie Fisher', 'Harrison Ford']
List
movie= 'Star Wars'
String
movieID=132
int
movieAwards = ('Oscar', 'Golden Globe', 'Director's Guild')
Tuple
movieRatings = {5:'language', 3:'violence'}
Dictionary
Explanation:
movieCost = 4.95
movieCost is of float type because it has a decimal point.
movieStars = ['Carrie Fisher', 'Harrison Ford']
movieStars if of list type because in Python the elements of list is inside square brackets.
List is an ordered collection. List is mutable i-e items can be added and remved from the list
movie = 'Star Wars'
movies is a string type because it is in enclosed in single quotes only.
movieID = 132
movieID is of int type because it is only number, without decimal value.
movieAwards = ('Oscar', 'Golden Globe', 'Director's Guild')
movieAwards is a tuple type because it is enclosed in round brackets or parenthesis.
Tuple is a sequence object. It is ordered collection of item. it is immutable.
movieRatings = {5:'language', 3:'violence'}
MovieRating is a dictionay type because it is in key-value pair. it is an unordered collection.
Answer:
Here is my code below: username = 'Polly1220' password = 'Bob' userInput = input("What is your username?\ n") if userInput == username: a=input("Password?\ n") if a == password: print("Welcome!") else: print("That is the wrong password.") else: print("That is the wrong username.")
It depends, how long has it been in the water, if it’s been in it for a good amount of time there just wait and let dry, don’t attempt to turn it on until it’s completely dry, that can cause a short circuit and could cause it to not turn on, i say 24 hours let it dry then attempt, it will most likely turn on but it will still be damaged. hoped this helped.