Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 months ago.
This post was edited and submitted for review 7 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I'm new to programming. My project is a credit card award points optimizer written in Python 3. I have a few dictionaries based on spending categories, with the keys/values representing my credit cards and their point multiplier for that category.
After showing the user the categories, it asks them to input which one they want to make a purchase in, and here's where I'm getting an error because the input is a string and my dictionary is a variable.
How can I convert the string into a variable, so that I can print the keys/values?
Example category and list of categories
dining = {'amex': '4x points'}
categories = ['dining', 'grocery']
input and call script
purchase_type = input('Which category is it?: ')
for category in categories:
if purchase_type == category:
You can put your various category dictionaries into a dictionary themselves. Then you can just plug the input like selected = categories[theirInputVariable]
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to solve this problem forever now, I am having a problem when I do a dictionary for the days and for the students I can't store the birthdays since they are dictionaries or maybe I am just lost, how can I write efficient code fr this simple problem
In this simulation question, we will simulate the birthday problem for the case where at least
3 students have the same birthday in a class with 200 students.
For the simulation you can consider this scenario: Assume a bag filled with
numbers from 1 to 365. Then let 200 students pick a ball and then put it back. The
number the students pick is their birthday. Convert this process into a ’function’
in your program, where the return is an array of size with 200 and filled with the
birthdays.
You could use python's random module to sample 200 numbers in the range 0-365 without duplicates: https://docs.python.org/3/library/random.html#random.sample
Something like:
from random import sample
random.sample(range(365), 200)
Does it have to be a dictionary? This may be simpler to do by using a list. By creating a list you can append every birthday drawn (in the case of scenario of the simulation) to the list and have the indices of list correspond to each student. ie. student 1: index 0 would have the birthday: list[index]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I've been away from Python for awhile, please forgive the broad/basic question.
Let's say I have a list of items, which can be anything really.
I want to write a program that prints two of these at a time, in every possible combination of two, and lets the user choose a preference/winner. Then at the end print the full list with some sort of numerical preference value for each. I don't know enough about the mathematics of rank or preference to know what that number would even look like...
Basically I'm having writer's block right from the start here. Any advice on how to structure this or what I should be looking into?
A very simple way of doing it would look something like this:
initialize a scoring_list
for every element in a list
for every element in a list
while valid input:
ask the question via raw_input()
if input matches the first item
store winner in some sort of scoring list
tell program input is valid
else if input matches the second item
store winner in some sort of scoring list
tell program input is valid
else
tell program input is not valid and repeat question
do some math with the scoring_list (e.g. normalization)
print( scoring_list )
Obviously a lot of detail is left out intentionally, because it depends on programming style and objectives. For example, it may be better to do the loops via indices so that you can have a scoring list with indices that matches your original list. With this structure, you can be creative with how you are tracking the "ranks" with something more statistically rigorous than a straight count.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm trying to create a machine learning algorithm, for address classification or similar address classification, for rural(Villages) areas. I have a historical data, which includes list of Addresses (Independent Variable), Village Name (Independent Variable) Pin-Codes (Independent Variable), Customer Mobile Number and Route No (Dependent Variable). Route No is for delivery cart, which will help them to cover maximum number of delivery destination in that area.
Challenges -
"Address" can be miss spelled.
"Villages Name" can be null.
"Pin-codes" can be wrong.
Good Thing -
Not all the independent variables can be wrong/null at the same time.
Now the point of creating this algorithm is for selecting the best Route Number, on the basis of "Address", "Villages", "Pin-Codes", and Historical Data(In which we have manually selected the Route for delivery carts).
I'm the beginner, i'm confused how to do this which process is to use.
Tasked I have done.
Address cleaning - Removed short words, Removed Big Words, Removed Stop Words.
Now trying to do it with word vector, but i'm not able to do that.
for this first you'll have to build a dataset first - consisting the names of as many villages as you can! because many villages have similar names so identifying a typo is pretty difficult and risky! there is a difference of one or two letters. So, bigger dataset is better.
Then, try to use TF-IDF on the combination of village name and PIN code (this link may be helpful for Indian data) or you can go for fuzzy logic.
Hope it helps! Happy coding!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
For an online assignment to be submitted for a MOOC, I have written a python program that takes in text data (The name, roll numbers, grades, etc of a list of students) in a particular format and prints the output after processing the data. The output is printed from a list of tuples using a for loop to iterate through the list and using the str.join() function to join the elements in the tuples.
The list of tuples is sorted already and when I run it in the Spyder IDE console, it prints the output in the order that it appears in the list. But, when I submit in the window of the online judge and run it, the output is obtained in a random order and my answer doesn't get accepted. Can anyone please help? I am all ready to clarify further if my question isn't clear.
Thank you.
As #Epo rightly pointed out, I tested my input with alphabetically sorted data while the online judge used the same data sorted differently as input. Adding a "sorted()" function to the input did the job.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a dataset of IT operations tickets with fields like Ticket No, Description, Category,SubCategory,Priority etc.
What I need to do is to use available data(except ticket no) to predict the ticket priority. Sample data shown below.
Number Priority Created_on Description Category Sub Category
719515 MEDIUM 05-01-2016 MedWay 3rd Lucene.... Server Change
720317 MEDIUM 07-01-2016 DI - Medway 13146409 Application Incident
720447 MEDIUM 08-01-2016 DI QLD Chermside.... Application Medway
Please guide me on this.
Answering without more is a bit tough, and this is more of a context questions than a code question. But here is the logic I would use to start to evaluate this problem Keep in mind it might involve writing a few separate scripts each performing part of the task.
Try breaking the problem up into smaller pieces.You cannot do an analysis without all the data so start by creating the data.
You have the category and sub category already make a list of all the unique factors in each list and create a set of weights for each based on your system and business needs. As you make subcategory weights, keep in mind how they will interact with categories (+/- as well as magnitude).
Write a script to read the description, count all the non-trivial words. Create some kind of classifications for words to help you build lists that will inform the model with categories and sub categories.
Is the value an error message, or machine name, or some other code or type of problem you can extract using key words?
How are all the word groupings meaningful?
How would the contribute to making a decision?
Think about the categories when you decide these things.
Then with all of the parts, decide on a model, build, test and refine. I know there is no code in this but the problem solving part of Data Science happens outside of code most of the time.
You need to come up with the code yourself. If you get stuck post an edit and we can help.