Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- One code that works is this:
- value_list = [1, 2, 1]
- distinct_values = 2
- Because the above code worked, I was trying to make an if and elif statement for each of the values for the answers in the value_list. The distinct_values would be changed depending on the value_list. This however doesn't work the way I want because I have probably messed up.
- For example, if the values_list was equal to [1,2,1] the distinct_values would be 2 and if values_list was [4,4,4,4,4,4] the distinct_values would be 1.
- If there is an easier way to try and solve this problem I would love to know how to do it.
- My attempt at an If and elif statement
- values_list = input()
- if value_list == [1, 2, 1]:
- distinct_values = 2
- elif value_list == []:
- distinct_values = 0
- elif value_list == [4, 4, 4, 4, 4, 4]:
- distinct_values = 2
- elif value_list == [1, 2, 3]:
- distinct_values = 3
- elif value_list == [1]:
- distinct_values = 1
- elif value_list == [1, 2, 1]:
- distinct_values = 2
- However, the program I am using says that I shouldn't be using these things: print statements or input statements
- https://imgur.com/a/B9HXvSE
- And that I should be using:
- len, set, ()
- https://imgur.com/a/Hl984wF
- Then I tried to do this:
- value_list = [1, 2, 1]
- distinct_values = set(value_list)
- print(len(distinct_values))
- The issue is that it uses the print statement and I am not allowed to use it, and it only works for one value_list and not all of the other ones. This does work in Visual Studio Code but not in MyProgramming Lab.
- I am very stuck on how to solve this assignment so any help would be greatly appreciated.
- Is there a way to solve this question using dictionaries?
- Something like this?
- value_list = {[1, 2, 1]: 2, [1, 2, 3] : 2, [1] : 1, [4, 4, 4, 4, 4, 4] : 1 }
- Then if the input is [1, 2, 1] it outputs distinct_values = 2.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement