Python 3 if/elif issue - qpython3

i have a if/elif statement in my code snippet below... for some reason even when i trigger the elif statement the console still prints the if statement instead of the elif... i'm sure i am missing something stupid.
use_stim = str.lower(input("Do you want to use this stimpak now?"))
if "ok" in use_stim or "okay" in use_stim or "yes" in use_stim or "sure" in use_stim or "you bet" or "good idea" in use_stim:
char_health = char_health + char_stim_heal
char_stims = char_stims - 1
print(char_name + ": Using stimpak, I feel better")
print("")
print("***STATS***")
print("Health:" + str(char_health))
print("Stimpaks:" + str(char_stims))
print("***STATS***")
print("")
search_next = str.lower(input(char_name + ": Alright, what's next? Weapons or amunition?"))
print(username + ": " + search_next)
elif "no" in use_stim or "nope" in use_stim or "never" in use_stim or "no way" in use_stim or "not a chance" in use_stim or "i don't think so" in use_stim:
print(user_name + ": " + use_stim)
print(char_name + ": Alright, i'll save it for later.")
char_stims = 1
char_health = 75
print("")
print("***STATS***")
print("Health:" + str(char_health))
print("Stimpaks:" + str(char_stims))
print("***STATS***")
print("")

It's because you're missing an in use_stim in the first if statement after the "You bet";
if "ok" in use_stim or "okay" in use_stim or "yes" in use_stim or "sure" in use_stim or "you bet" in use_stim or "good idea" in use_stim:
char_health = char_health + char_stim_heal
char_stims = char_stims - 1
print(char_name + ": Using stimpak, I feel better")
print("")
print("***STATS***")
print("Health:" + str(char_health))
print("Stimpaks:" + str(char_stims))
print("***STATS***")
print("")
search_next = str.lower(input(char_name + ": Alright, what's next? Weapons or amunition?"))
print(username + ": " + search_next)
elif "no" in use_stim or "nope" in use_stim or "never" in use_stim or "no way" in use_stim or "not a chance" in use_stim or "i don't think so" in use_stim:
print(user_name + ": " + use_stim)
print(char_name + ": Alright, i'll save it for later.")
char_stims = 1
char_health = 75
print("")
print("***STATS***")
print("Health:" + str(char_health))
print("Stimpaks:" + str(char_stims))
print("***STATS***")
print("")
This should work now.
A couple of notes for you if you want;
You can add the extra line between print statements using /n so you can remove the print("") statements and add \n to the previous statement e.g;
print(char_name + ": Using stimpak, I feel better\n") <<< Add \n here
print("") <<< Remove this
print("***STATS***")
print("Health:" + str(char_health))
print("Stimpaks:" + str(char_stims))
print("***STATS***\n") <<< Add \n here
print("") <<< Remove this
The use of in will search for the text you've specified anywhere in the string, so "no" in use_stim will work for no, nope, no way and not a chance, therefore you can simplify the elif statement to;
elif "no" in use_stim or "never" in use_stim or "i don't think so" in use_stim:

Related

FabricJS Android Webview Newlines showing as \n

So I load a basic page with the canvas and everything seems to work except newlines are shown as \n
here is the body as a java method:
input = StringEscapeUtils.unescapeShell(this.getData());
private String htmlBody(String input){
return "<html><head>" +
"<link href=\"fonts.css\" type=\"text/css\" rel=\"stylesheet\" />" +
"<script src=\"jquery.min.js\" type=\"text/javascript\"></script>" +
"<script src=\"fontfaceobserver.js\" type=\"text/javascript\"></script>" +
"<script src=\"fabric.min.js\" type=\"text/javascript\"></script>" +
"<style type=\"text/css\">" +
".canvas-container {" +
"margin: 0 auto;" +
"}"+
"</style>" +
"<script src=\"javascript_fabric.js\" type=\"text/javascript\"></script>" +
"</head><body>"+
"<div id=\"sb2div\" class=\"row\" style=\"margin: 0 auto!important; max-height: 100vh\">" +
"<canvas id=\"fabricjs-branding\" width=\"600\" height=\"600\" style=\"margin: auto!important;\"></canvas>" +
"</div>" +
"<script>" +
"$(document).ready(function(){" +
"setUpBranding();" +
"var o = " + input + ";" +
"console.log(o);" +
"fabricjscanvas.loadFromJSON(o);"+
"});" +
"</script>" +
"</body></html>";
}
setUpBranding() does my initialization of fabricjscanvas which does add some feature prototypes but the issue has nothing to do with them.
itext and textbox are standard using the current release 4
on the desktop using the same setup everything is fine...
based on a comment i found the newline characters were not getting unescaped with the rest of the json data... strange but I was able to fix it using the Java String Replace method... after using the StringEscapeUtils.unescapeShell
input = StringEscapeUtils.unescapeShell(this.getData());
input = input.replace("\\\\n", "\\n");

Default instance of RoutingSearchParameters not working

I cannot run a solution with routing parameters because the method does not accept the default RoutingSearchParameters because the instance is empty (every field is set to 0).
Here is how I'm creating the instance:
// final var p = RoutingSearchParameters.newBuilder().build(); Both don't work
final var p = RoutingSearchParameters.getDefaultInstance();
final var s = routing.solveWithParameters(p);
Here is the error (happens for every single field):
E0717 20:27:26.682358 6108 routing.cc:1886] Invalid RoutingSearchParameters: Invalid cheapest_insertion_first_solution_neighbors_ratio: 0
Is there any way to solve it without manually setting every field?
All parameters default are visible here:
https://github.com/google/or-tools/blob/45770b833997f827d322e929b1ed4781c4e60d44/ortools/constraint_solver/routing_parameters.cc#L45
"first_solution_strategy: AUTOMATIC "
"use_unfiltered_first_solution_strategy: false "
"savings_neighbors_ratio: 1 "
"savings_max_memory_usage_bytes: 6e9 "
"savings_add_reverse_arcs: false "
"savings_arc_coefficient: 1 "
"savings_parallel_routes: false "
"cheapest_insertion_farthest_seeds_ratio: 0 "
"cheapest_insertion_first_solution_neighbors_ratio: 1 "
"cheapest_insertion_ls_operator_neighbors_ratio: 1 "
"local_search_operators {"
" use_relocate: BOOL_TRUE"
" use_relocate_pair: BOOL_TRUE"
" use_light_relocate_pair: BOOL_TRUE"
" use_relocate_subtrip: BOOL_TRUE"
" use_relocate_neighbors: BOOL_FALSE"
" use_exchange: BOOL_TRUE"
" use_exchange_pair: BOOL_TRUE"
" use_exchange_subtrip: BOOL_TRUE"
" use_cross: BOOL_TRUE"
" use_cross_exchange: BOOL_FALSE"
" use_relocate_expensive_chain: BOOL_TRUE"
" use_two_opt: BOOL_TRUE"
" use_or_opt: BOOL_TRUE"
" use_lin_kernighan: BOOL_TRUE"
" use_tsp_opt: BOOL_FALSE"
" use_make_active: BOOL_TRUE"
" use_relocate_and_make_active: BOOL_FALSE" // costly if true by default
" use_make_inactive: BOOL_TRUE"
" use_make_chain_inactive: BOOL_FALSE"
" use_swap_active: BOOL_TRUE"
" use_extended_swap_active: BOOL_FALSE"
" use_node_pair_swap_active: BOOL_TRUE"
" use_path_lns: BOOL_FALSE"
" use_full_path_lns: BOOL_FALSE"
" use_tsp_lns: BOOL_FALSE"
" use_inactive_lns: BOOL_FALSE"
" use_global_cheapest_insertion_path_lns: BOOL_TRUE"
" use_local_cheapest_insertion_path_lns: BOOL_TRUE"
" use_global_cheapest_insertion_expensive_chain_lns: BOOL_FALSE"
" use_local_cheapest_insertion_expensive_chain_lns: BOOL_FALSE"
"}"
"relocate_expensive_chain_num_arcs_to_consider: 4 "
"heuristic_expensive_chain_lns_num_arcs_to_consider: 4 "
"local_search_metaheuristic: AUTOMATIC "
"guided_local_search_lambda_coefficient: 0.1 "
"use_depth_first_search: false "
"use_cp: BOOL_TRUE "
"use_cp_sat: BOOL_FALSE "
"continuous_scheduling_solver: GLOP "
"mixed_integer_scheduling_solver: CP_SAT "
"optimization_step: 0.0 "
"number_of_solutions_to_collect: 1 "
// No "time_limit" by default.
"solution_limit: 0x7fffffffffffffff " // kint64max
"lns_time_limit: { seconds:0 nanos:100000000 } " // 0.1s
"use_full_propagation: false "
"log_search: false "
"log_cost_scaling_factor: 1.0 "
"log_cost_offset: 0.0";
As pointed by a comment: the proper way to instantiate the RoutingSearchParameters class is by importing com.google.ortools.constraintsolver.main and then use the method main.defaultRoutingSearchParameters().

flink error Could not find a suitable table factory for 'org.apache.flink.table.factories.BatchTableSourceFactory' in the classpath

I'm new to Apache Flink and I'm trying to read an Avro file as follows,
val schema = new Schema()
.field("tconst", "string")
.field("titleType", "string")
.field("primaryTitle", "string")
.field("originalTitle", "string")
.field("isAdult", "int")
.field("startYear", "string")
.field("endYear", "string")
.field("runtimeMinutes", "int")
.field("genres", "string")
val avroFormat: Avro = new Avro()
.avroSchema(
"{" +
" \"type\": \"record\"," +
" \"name\": \"test\"," +
" \"fields\" : [" +
" {\"name\": \"tconst\", \"type\": \"string\"}," +
" {\"name\": \"titleType\", \"type\": \"string\"}" +
" {\"name\": \"primaryTitle\", \"type\": \"string\"}" +
" {\"name\": \"originalTitle\", \"type\": \"string\"}" +
" {\"name\": \"isAdult\", \"type\": \"int\"}" +
" {\"name\": \"startYear\", \"type\": \"string\"}" +
" {\"name\": \"endYear\", \"type\": \"string\"}" +
" {\"name\": \"runtimeMinutes\", \"type\": \"int\"}" +
" {\"name\": \"genres\", \"type\": \"string\"}" +
" ]" +
"}"
)
tableEnv.connect(new FileSystem().path("/Users/x/Documents/test_1.avro"))
.withSchema(schema)
.withFormat(avroFormat)
.registerTableSource("sink")
But when I run this I got the following error.
Exception in thread "main" org.apache.flink.table.api.NoMatchingTableFactoryException: Could not find a suitable table factory for 'org.apache.flink.table.factories.BatchTableSourceFactory' in
the classpath.
Reason: No context matches.
The following properties are requested:
connector.path=/Users/x/Documents/test_1.avro
connector.property-version=1
connector.type=filesystem
format.avro-schema=.... // above schema
format.property-version=1
format.type=avro
schema.0.name=tconst
schema.0.type=string
schema.1.name=titleType
schema.1.type=string
schema.2.name=primaryTitle
schema.2.type=string
schema.3.name=originalTitle
schema.3.type=string
schema.4.name=isAdult
schema.4.type=int
schema.5.name=startYear
schema.5.type=string
schema.6.name=endYear
schema.6.type=string
schema.7.name=runtimeMinutes
schema.7.type=int
schema.8.name=genres
schema.8.type=string
The following factories have been considered:
org.apache.flink.api.java.io.jdbc.JDBCTableSourceSinkFactory
org.apache.flink.table.sources.CsvBatchTableSourceFactory
org.apache.flink.table.sources.CsvAppendTableSourceFactory
org.apache.flink.table.sinks.CsvBatchTableSinkFactory
org.apache.flink.table.sinks.CsvAppendTableSinkFactory
org.apache.flink.formats.avro.AvroRowFormatFactory
org.apache.flink.streaming.connectors.kafka.KafkaTableSourceSinkFactory
In this Avro file it has a Flink Dataset and used AvroOutputFormat to write the file.
val avroOutputFormat = new AvroOutputFormat[Row](classOf[Row])
flinkDatase.write(avroOutputFormat, "/Users/x/Documents/test_1.avro").setParallelism(1)
I'm thinking, if it's a wrong type of data that could result the mentioned error. Is there a way to identify the exact problem of this?
Sorry for misguiding you. As of now, Filesystem connector unfortunately does not support Avro.
So there is no option but to use dataset API. I recommend to use avrohugger to generate an appropriate scala class for your avro schema.
// convert to your scala class
val dsTuple: DataSet[User] = tableEnv.toDataSet[User](table)
// write out
val avroOutputFormat = new AvroOutputFormat<>(User.class)
avroOutputFormat.setCodec(Codec.SNAPPY)
avroOutputFormat.setSchema(User.SCHEMA$)
specificUser.write(avroOutputFormat, outputPath1)

Getting Object tag value in AWS S3

I am using scala to get information about my objects that are in S3 I am intersted in getting each object I have inside S3 Bucket his tag value so far I have accomplished this code to get me information about my objects but did not succeeded in getting its tagging value: I used this code in scala:
def retrieveObjectTags(keyName: String): Unit ={
try {
println("Listing objects")
val req: ListObjectsV2Request =
new ListObjectsV2Request().withBucketName(bucketName).withMaxKeys(2)
var result: ListObjectsV2Result = null
do {
result = client.listObjectsV2(req)
for (objectSummary <- result.getObjectSummaries) {
println(
" - " + objectSummary.getKey + " " + "(size = " + objectSummary.getSize +
")")
println(objectSummary.getETag)
}
println("Next Continuation Token : " + result.getNextContinuationToken)
req.setContinuationToken(result.getNextContinuationToken)
} while (result.isTruncated == true);
}catch {
case ase: AmazonServiceException => {
println(
"Caught an AmazonServiceException, " + "which means your request made it " +
"to Amazon S3, but was rejected with an error response " +
"for some reason.")
println("Error Message: " + ase.getMessage)
println("HTTP Status Code: " + ase.getStatusCode)
println("AWS Error Code: " + ase.getErrorCode)
println("Error Type: " + ase.getErrorType)
println("Request ID: " + ase.getRequestId)
}
case ace: AmazonClientException => {
println(
"Caught an AmazonClientException, " + "which means the client encountered " +
"an internal error while trying to communicate" +
" with S3, " +
"such as not being able to access the network.")
println("Error Message: " + ace.getMessage)
}
}
// val getTaggingRequest = new GetObjectTaggingRequest(bucketName,keyName)
// var getTagResult = client.getObjectTagging(getTaggingRequest)
//println(getTaggingRequest)
var tag: Tag = new Tag()
println("tag name:" + tag.getValue)
}
as for the remarked lines I have encounter a problem with it, what other way I can use to solve this problem?

Error C#.NET 3.0: The best overloaded method match for 'CreatePageSection(ref string, ref string, ref object)' has some invalid arguments

I have got the following problem. I encountered an error regarding the default parameters. I added a simple piece of code for an overload. Now I get in the new code (line 3: CreatePageSection(sItemID, "", null);) gives the error mentioned in the title.
I looked for the answer in the other topics, but I can't find the problem. Can someone help me?
The code is found here:
public void CreatePageSection(ref string sItemID)
{
CreatePageSection(sItemID, "", null);
}
public void CreatePageSection(ref string sItemID, ref string sFrameUrl, ref object vOnReadyState)
{
if (Strings.InStr(msPresentPageSections, "|" + sItemID + "|", 0) > 0) {
return;
}
msPresentPageSections = msPresentPageSections + sItemID + "|";
string writeHtml = "<div class=" + MConstants.QUOTE + "PageSection" + MConstants.QUOTE + " id=" + MConstants.QUOTE + "Section" + sItemID + "Div" + MConstants.QUOTE + " style=" + MConstants.QUOTE + "display: none;" + MConstants.QUOTE + ">";
this.WriteLine_Renamed(ref writeHtml);
//UPGRADE_WARNING: Couldn't resolve default property of object vOnReadyState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
//UPGRADE_NOTE: IsMissing() was changed to IsNothing_Renamed(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8AE1CB93-37AB-439A-A4FF-BE3B6760BB23"'
writeHtml = " <iframe id=" + MConstants.QUOTE + sItemID + "Frame" + MConstants.QUOTE + " name=" + MConstants.QUOTE + sItemID + "Frame" + MConstants.QUOTE + " frameborder=" + MConstants.QUOTE + "0" + MConstants.QUOTE + (!string.IsNullOrEmpty(sFrameUrl) ? " src=" + MConstants.QUOTE + sFrameUrl + MConstants.QUOTE : "") + ((vOnReadyState == null) ? "" : " onreadystatechange=" + MConstants.QUOTE + Convert.ToString(vOnReadyState) + MConstants.QUOTE) + ">";
this.WriteLine_Renamed(ref writeHtml);
writeHtml = " </iframe>";
this.WriteLine_Renamed(ref writeHtml);
writeHtml = "</div>";
this.WriteLine_Renamed(ref writeHtml);
}
you must pass params by reference
public void CreatePageSection(ref string sItemID)
{
var missingString = String.Empty;
object missingObject = null;
CreatePageSection(ref sItemID, ref missingString, ref missingObject);
}
Since your are not manipulating sFrameUrl and vOnReadyState, remove the ref keyword from those parameters.
See: http://msdn.microsoft.com/en-us/library/14akc2c7(v=vs.71).aspx
hth
Mario