Generic discussion about OneLang. Please read the FAQ first! (https://github.com/koczkatamas/onelang/wiki/FAQ)
def replace(good,bad,name):
file = open(name)
contents = file.read()
contents = contents[:-4]
file.seek(0)
bad_keys = list(bad.keys())
bad_keys.sort(key = lambda x:len(x),reverse=True)
good_keys = list(good.keys())
good_keys.sort(key=lambda x: len(x), reverse=True)
for i in bad_keys:
if i in contents:
for k in good_keys:
if good[k] == bad[i] and len(i.split()) == len(k.split()):
contents = contents.replace(i,k)
break
print(contents)
def file_score(good,bad,name):
bad_score = 0
good_score = 0
file = open(name)
for i in sorted(bad.keys()):
if i in file.read():
file.seek(0)
bad_score += bad[i](file.read()).count(i)
file.seek(0)
for i in sorted(good.keys()):
if i in file.read():
file.seek(0)
good_score += good[i](file.read()).count(i)
file.seek(0)
print(good_score,bad_score,sep='\n')
if bad_score > good_score:
replace(good,bad,name)
else:
file.seek(0)
print(file.read()[:-4])
file.close()
bad = {'bad': 5, 'worse': 3, 'worst': 6, 'very bad': 5, 'bad luck': 7, 'bad mood': 6}
good = {'great': 6, 'good': 5, 'nice': 3, 'very good': 5, 'very great': 7, 'good mood': 6}
name = input()
file_score(good,bad,name)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Task2
{
class MyBigInteger
{
public void AddSame(string s1, string s2) //A class that takes two strings, parses its indexes into integers and adds them to output a perfect added result
{
int n = s1.Length;
int[] container = new int[n];
bool check = false;
int save=0;
for (int i = s1.Length - 1; i >= 0; i--)
{
int first = (int)char.GetNumericValue(s1[i]); //int first = Convert.ToInt32(s1[i].ToString);
int second = (int)char.GetNumericValue(s2[i]); //int second = Convert.ToInt32(s2[i].ToString);
if (check == true)
{
save = first+second+1;
check = false;
}
else if (check == false)
{
save = first+second;
}
if (save < 10)
{
container[i] = save;
}
else
{
int tertiary = save % 10;
container[i] = tertiary;
check = true;
}
}
foreach (int val in container)
{
Console.Write(val);
}
Console.WriteLine();
}
public void AddDifferent(string s1,string s2) { //a class that takes two strings of different lengths and adds them
int lengthStringOne = s1.Length;
int lengthStringTwo = s2.Length;
int length = 0;
int difference = 0;
bool check = false;
int save = 0;
if (lengthStringOne > lengthStringTwo)
{
length = lengthStringOne;
difference = lengthStringOne - lengthStringTwo;
}
else if (lengthStringTwo > lengthStringOne)
{
length = lengthStringTwo;
difference = lengthStringTwo - lengthStringOne;
}
else if (lengthStringOne == lengthStringTwo)
{
length = lengthStringOne;
}
int[] container = new int[length];
for (int i = length - 1; i >= 0; i--)
{
int first=0, second=0;
if (lengthStringOne > lengthStringTwo)
{
first = Convert.ToInt32(s1[i].ToString());
if (difference <= i)
{
int temp = i - difference;
second = Convert.ToInt32(s2[temp].ToString());
}
else if (difference > i)
{
second = 0;
}
}
else if (lengthStringTwo > lengthStringOne)
{
second = Convert.ToInt32(s2[i].ToString());
if (difference <= i)
{
int temp = i - difference;
first = Convert.ToInt32(s1[temp].ToString());
}
else if (difference > i)
{
first = 0;
}
}
else if (lengthStringOne == lengthStringTwo)
{
first = Convert.ToInt32(s1[i].ToString());
second = Convert.ToInt32(s2[i].ToString());
}
if (check == true)
{
save = first + second + 1;
check = false;
}
else if (check == false)
{
save = first + second;
}
if (save < 10)
{
container[i] = save;
}
else
{
int tertiary = save % 10;
{% for product, range, nSlides in allProds %}
<h1>Grocery</h1>
<div
id="demo{{forloop.counter}}"
class="carousel slide my-3"
data-ride="carousel"
>
<ul class="carousel-indicators">
<li
data-target="#demo{{forloop.counter}}"
data-slide-to="0"
class="active"
></li>
{% for i in range %}
<li
data-target="#demo{{forloop.parentloop.counter}}"
data-slide-to="{{i}}"
></li>
{% endfor %}
</ul>
<div class="container carousel-inner no-padding">
<div class="carousel-item active">
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="card" style="width: 18rem">
<img
src="/media/{{product.0.image}}"
class="card-img-top"
alt="..."
/>
<div class="card-body">
<h5 class="card-title">{{product.0.product_name}}</h5>
<p class="card-text">{{product.0.desc}}</p>
<a href="#" class="btn btn-primary">Add to Cart</a>
</div>
</div>
</div>
{% for i in product|slice:"1:"%}
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="card" style="width: 18rem">
<img src="/media/{{i.image}}" class="card-img-top" alt="..." />
<div class="card-body">
<h5 class="card-title">{{i.product_name}}</h5>
<p class="card-text">{{i.desc}}</p>
<a href="#" class="btn btn-primary">Add To Cart</a>
</div>
</div>
</div>
{% if forloop.counter|divisibleby:3 and forloop.counter > 0 and not
forloop.last %}
</div>
<div class="carousel-item">{% endif %} {% endfor %}</div>
</div>
</div>
<!-- left and right controls for the slide -->
<a
class="carousel-control-prev"
href="#demo{{forloop.counter}}"
data-slide="prev"
>
<span class="carousel-control-prev-icon"></span>
</a>
<a
class="carousel-control-next"
href="#demo{{forloop.counter}}"
data-slide="next"
>
<span class="carousel-control-next-icon"></span>
</a>
{% endfor%} </div> can anyone just translate this code into react or javscript code for me??