GVKun编程网logo

尝试做信用计算器,但总和不能正确添加

20

本文将为您提供关于尝试做信用计算器,但总和不能正确添加的详细介绍,同时,我们还将为您提供关于bash–在python解释器提示符中添加颜色,不能正确包装、ggplot位置堆栈未正确添加值、java–如

本文将为您提供关于尝试做信用计算器,但总和不能正确添加的详细介绍,同时,我们还将为您提供关于bash – 在python解释器提示符中添加颜色,不能正确包装、ggplot 位置堆栈未正确添加值、java – 如何正确添加侦听器以滑行、JavaScript费用计算器的实用信息。

本文目录一览:

尝试做信用计算器,但总和不能正确添加

尝试做信用计算器,但总和不能正确添加

由于输入存储和返回了这些数字作为 strings ,因此您可以使用parseFloat将其转换为数字,然后再将其用于数学运算:

function result() {

const sum = parseFloat(document.getElementById('sum').value);
const percent = parseFloat(document.getElementById('percentage').value);
const months = parseFloat(document.getElementById('months').value);


let text = sum * (percent / 100 ) * months;
let resultat = sum + text;
  console.log(resultat);
    return document.getElementById('result').innerHTML = '$ ' + resultat;

}
<div>

<input type="text" id="sum" placeholder="Enter sum..$">
<input type="text" id="percentage" placeholder="Enter %..">
<input type="text" id="months" placeholder="Enter months..">
<button id="calculate" onClick="result()">
Calculate
</button><br><br>
To payback:
<p id="result">
 </p>

</div>

bash – 在python解释器提示符中添加颜色,不能正确包装

bash – 在python解释器提示符中添加颜色,不能正确包装

我想在终端上有一个更加丰富多彩的 Python提示,只是为了便于阅读.我目前有:
sys.ps1 = '\033[96m>>> \033[0m'
sys.ps2 = '\033[96m... \033[0m'

在我的PYTHONSTARTUP文件中,它根据需要为其提供颜色.但是,行上的任何文本都不能正确包装.文本到达行的末尾,而不是立即开始新行,在开始换行之前开始覆盖第一行的开头.正如您可能想象的那样,这实际上是不可读的.我该如何解决这个问题?

请尝试以下方法:
sys.ps1 = '\001\033[96m\002>>> \001\033[0m\002'
sys.ps2 = '\001\033[96m\002... \001\033[0m\002'

This answer to a similar question explains why the \001 and \002 are necessary.

ggplot 位置堆栈未正确添加值

ggplot 位置堆栈未正确添加值

这是一种解决方法,使用position = "identity"

library(ggplot2)
library(forcats)
library(dplyr)

gapminder::gapminder %>% 
  filter(continent %in% c("Asia","Europe"),year == 2007) %>% 
  mutate(country = fct_reorder(country,-gdpPercap)) %>% 
  group_by(continent) %>% 
  sample_n(5) %>% 
  arrange(country) %>% 
  ggplot(aes(continent,gdpPercap,fill = country)) +
  geom_bar(stat = "identity",position = "identity")

希望能满足您的要求 - 每个国家/地区的标准都达到了自己的 gdpPercap(不会增加到低于它的国家/地区):

您可能想尝试使用您的数据来查看它是否清晰,但也许部分 position = "dodge" 有助于表明条形是独立的,并且每个条形都一直下降到零?

由 reprex package (v1.0.0) 于 2021 年 3 月 15 日创建

轻微修改 - 其他可能性:

您可以使用 position = position_dodge(width = 0.7)(不只是“躲避”)使它们稍微重叠,但仍然显示每个条形变为零:

library(ggplot2)
library(forcats)
library(dplyr)

gapminder::gapminder %>% 
  filter(continent %in% c("Asia",position = position_dodge(width = 0.7))

由 reprex package (v1.0.0) 于 2021 年 3 月 15 日创建

java – 如何正确添加侦听器以滑行

java – 如何正确添加侦听器以滑行

我正在使用滑动来显示专辑封面但不知何故我无法显示它.我想添加侦听器以滑动以查找错误,但它无法正常工作.它显示错误说:

listener(com.bumptech.glide.request.RequestListener) in com.bumptech.glide.DrawableRequestBuilder cannot be applied to (anonymous com.bumptech.glide.request.RequestListener)

PlayListActivity.java:

package com.example.dell_1.myapp3;


import android.app.Activity;
import android.database.Cursor;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import java.io.File;
import java.io.IOException;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;


public class PlayListActivity extends Activity {

    private String[] mAudioPath;
    private MediaPlayer mMediaPlayer;
    private String[] mMusicList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_list);

        mMediaPlayer = new MediaPlayer();
        ListView mListView = (ListView) findViewById(R.id.list);

        mMusicList = getAudioList();

        ArrayAdapter<String> mAdapter = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, mMusicList);
        mListView.setAdapter(mAdapter);

        mListView.setonItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View view, int arg2,
                                    long arg3) {

                try {
                    playSong(mAudioPath[arg2]);
                } catch (IllegalArgumentException e) {
                    e.printstacktrace();
                } catch (IllegalStateException e) {
                    e.printstacktrace();
                } catch (IOException e) {
                    e.printstacktrace();
                }

            }
        });
    }

    private String[] getAudioList() {
        final Cursor mCursor = getContentResolver().query(
                MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
                new String[]{MediaStore.Audio.Media.disPLAY_NAME, MediaStore.Audio.Media.DATA}, null, null,
                "LOWER(" + MediaStore.Audio.Media.TITLE + ") ASC");

        int count = mCursor.getCount();

        String[] songs = new String[count];
        mAudioPath = new String[count];
        int i = 0;
        if (mCursor.movetoFirst()) {
            do {
                songs[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.disPLAY_NAME));
                mAudioPath[i] = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
                i++;
            } while (mCursor.movetoNext());
        }

        mCursor.close();

        return songs;
    }

    private void playSong(String path) throws IllegalArgumentException,
            IllegalStateException, IOException {

        setContentView(R.layout.activity_android_building_music_player);
        Log.d("ringtone", "playSong :: " + path);

        mMediaPlayer.reset();
        mMediaPlayer.setDataSource(path);
//mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();

        asd();
    }

    public void asd(){
        File music = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
// Tested with music from Windows 7's c:\Users\Public\Music\Sample Music
        String mAudioPath = new File(music, "Maid with the Flaxen Hair.mp3").getAbsolutePath();
        ImageView imageView = (ImageView) findViewById(R.id.coverart);
        Glide
                .with(this)
                .load(new AudioCover(mAudioPath))
                .placeholder(R.drawable.adele1)
                .error(R.drawable.adele1)
                .listener(new RequestListener<Uri, GlideDrawable>() {
                    @Override public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
                        return false;
                    }
                    @Override public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        // easy
                        return false;
                        // impossible?
                    }
                })
                .into(imageView)
        ;
    }
}

AudioCover.java:

package com.example.dell_1.myapp3;

import android.content.Context;
import android.media.MediaMetadataRetriever;

import com.bumptech.glide.*;
import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.model.GenericLoaderFactory;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import com.bumptech.glide.load.model.stream.StreamModelLoader;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class AudioCover {
    final String path;
    public AudioCover(String path) {
        this.path = path;
    }
}

class AudioCoverLoader implements StreamModelLoader<AudioCover> {
    @Override public DataFetcher<InputStream> getResourceFetcher(AudioCover model, int width, int height) {
        return new AudioCoverFetcher(model);
    }

    static class Factory implements ModelLoaderFactory<AudioCover, InputStream> {
        @Override public ModelLoader<AudioCover, InputStream> build(Context context, GenericLoaderFactory factories) {
            return new AudioCoverLoader();
        }
        @Override public void teardown() {
        }
    }
}
class AudioCoverFetcher implements DataFetcher<InputStream> {
    private final AudioCover model;
    private FileInputStream stream;

    public AudioCoverFetcher(AudioCover model) {
        this.model = model;
    }

    @Override public String getId() {
        return model.path;
    }

    @Override public InputStream loadData(Priority priority) throws Exception {
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            retriever.setDataSource(model.path);
            byte[] picture = retriever.getEmbeddedPicture();
            if (picture != null) {
                return new ByteArrayInputStream(picture);
            } else {
                return fallback(model.path);
            }
        } finally {
            retriever.release();
        }
    }

    private static final String[] FALLBACKS = {"cover.jpg", "album.jpg", "folder.jpg"};
    private InputStream fallback(String path) throws FileNotFoundException {
        File parent = new File(path).getParentFile();
        for (String fallback : FALLBACKS) {
            // Todo make it smarter by enumerating folder contents and filtering for files
            // example algorithm for that: http://askubuntu.com/questions/123612/how-do-i-set-album-artwork
            File cover = new File(parent, fallback);
            if (cover.exists()) {
                return stream = new FileInputStream(cover);
            }
        }
        return null;
    }

    @Override public void cleanup() {
        // already cleaned up in loadData and ByteArrayInputStream will be GC'd
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException ignore) {
                // can't do much about it
            }
        }
    }
    @Override public void cancel() {
        // cannot cancel
    }
}

解决方法:

RequestListener< T,R>期望T是你在load()中提供的模型,在你的情况下T =?超级AudioCover(documentation):

// ...
.listener(new RequestListener<AudioCover, GlideDrawable>() {
    @Override
    public boolean onException(Exception e, AudioCover model, Target<GlideDrawable> target, boolean isFirstResource) {
        return false;
    }

    @Override
    public boolean onResourceReady(GlideDrawable resource, AudioCover model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
        return false;
    }
})
// ...

注意,自版本4.0.0-RC0 RequestListener< T,R>不推荐使用RequestListener< R>,在新的javadoc中查找更多信息.

JavaScript费用计算器

JavaScript费用计算器

我有这个JavaScript费用计算器,由于某种原因我无法在div中显示我的费用总额.有人可以告诉我哪里出错了吗?它应该是费用的运行记录,但我不知道为什么代码不会在这个代码片段中运行?或者是否可以将其更改为jQuery我刚下载2.1.0?

http://jsfiddle.net/bd0eL69b/

//Set up an associative array
//The keys represent the size of the cake
//The values represent the cost of the cake i.e A 10" cake cost's $35
 var cake_prices = new Array();
 cake_prices["Round6"]=20;
 cake_prices["Round8"]=25;
 cake_prices["Round10"]=35;
 cake_prices["Round12"]=75;
 
 //Set up an associative array 
 //The keys represent the filling type
 //The value represents the cost of the filling i.e. Lemon filling is $5,dobash filling is $9
 //We use this this array when the user selects a filling from the form
 var filling_prices= new Array();
 filling_prices["None"]=0;
 filling_prices["Lemon"]=5;
 filling_prices["Custard"]=5;
 filling_prices["Fudge"]=7;
 filling_prices["Mocha"]=8;
 filling_prices["RaspBerry"]=10;
 filling_prices["Pineapple"]=5;
 filling_prices["dobash"]=9;
 filling_prices["Mint"]=5;
 filling_prices["Cherry"]=5;
 filling_prices["Apricot"]=8;
 filling_prices["Buttercream"]=7;
 filling_prices["Chocolate Mousse"]=12;
 
	 
	 
// getCakeSizePrice() finds the price based on the size of the cake.
// Here, we need to take user's the selection from radio button selection
function getCakeSizePrice()
{  
    var cakeSizePrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the cake the user Chooses name=selectedCake":
    var selectedCake = theForm.elements["selectedcake"];
    //Here since there are 4 radio buttons selectedCake.length = 4
    //We loop through each radio buttons
    for(var i = 0; i < selectedCake.length; i++)
    {
        //if the radio button is checked
        if(selectedCake[i].checked)
        {
            //we set cakeSizePrice to the value of the selected radio button
            //i.e. if the user choose the 8" cake we set it to 25
            //by using the cake_prices array
            //We get the selected Items value
            //For example cake_prices["Round8".value]"
            cakeSizePrice = cake_prices[selectedCake[i].value];
            //If we get a match then we break out of this loop
            //No reason to continue if we get a match
            break;
        }
    }
    //We return the cakeSizePrice
    return cakeSizePrice;
}

//This function finds the filling price based on the 
//drop down selection
function getFillingPrice()
{
    var cakeFillingPrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the select id="filling"
     var selectedFilling = theForm.elements["filling"];
     
    //set cakeFilling Price equal to value user chose
    //For example filling_prices["Lemon".value] would be equal to 5
    cakeFillingPrice = filling_prices[selectedFilling.value];

    //finally we return cakeFillingPrice
    return cakeFillingPrice;
}

//candlesPrice() finds the candles price based on a check Box selection
function candlesPrice()
{
    var candlePrice=0;
    //Get a reference to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkBox id="includecandles"
    var includeCandles = theForm.elements["includecandles"];

    //If they checked the Box set candlePrice to 5
    if(includeCandles.checked==true)
    {
        candlePrice=5;
    }
    //finally we return the candlePrice
    return candlePrice;
}

function insciptionPrice()
{
    //This local variable will be used to decide whether or not to charge for the inscription
    //If the user checked the Box this value will be 20
    //otherwise it will remain at 0
    var inscriptionPrice=0;
    //Get a refernce to the form id="cakeform"
    var theForm = document.forms["cakeform"];
    //Get a reference to the checkBox id="includeinscription"
    var includeInscription = theForm.elements["includeinscription"];
    //If they checked the Box set inscriptionPrice to 20
    if(includeInscription.checked==true){
        inscriptionPrice=20;
    }
    //finally we return the inscriptionPrice
    return inscriptionPrice;
}
        
function calculatetotal()
{
    //Here we get the total price by calling our function
    //Each function returns a number so by calling them we add the values they return together
    var cakePrice = getCakeSizePrice() + getFillingPrice() + candlesPrice() + insciptionPrice();
    
    //display the result
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='block';
    divobj.innerHTML = "Total Price For the Cake $"+cakePrice;

}

function hidetotal()
{
    var divobj = document.getElementById('totalPrice');
    divobj.style.display='none';
}
<label><input type="radio"  name="selectedcake" value="Round6" onclick="calculatetotal()" />Round cake 6" -  serves 8 people ($20)</label><br/>
                <label><input type="radio"  name="selectedcake" value="Round8" onclick="calculatetotal()" />Round cake 8" - serves 12 people ($25)</label><br/>
                <label><input type="radio"  name="selectedcake" value="Round10" onclick="calculatetotal()" />Round cake 10" - serves 16 people($35)</label><br/>
                <label><input type="radio"  name="selectedcake" value="Round12" onclick="calculatetotal()" />Round cake 12" - serves 30 people($75)</label><br/>
                <br/>
                <label >Filling</label>
         
                <select id="filling" name='filling' onchange="calculatetotal()">
                <option value="None">Select Filling</option>
                <option value="Lemon">Lemon($5)</option>
                <option value="Custard">Custard($5)</option>
                <option value="Fudge">Fudge($7)</option>
                <option value="Mocha">Mocha($8)</option>
                <option value="RaspBerry">RaspBerry($10)</option>
                <option value="Pineapple">Pineapple($5)</option>
                <option value="dobash">dobash($9)</option>
                <option value="Mint">Mint($5)</option>
                <option value="Cherry">Cherry($5)</option>
                <option value="Apricot">Apricot($8)</option>
                <option value="Buttercream">Buttercream($7)</option>
                <option value="Chocolate Mousse">Chocolate Mousse($12)</option>
               </select>
                <br/>
                <p>
                <label for='includecandles'>Include Candles($5)</label>
               <input type="checkBox" id="includecandles" name='includecandles' onclick="calculatetotal()" />
               </p>
               
                <p>
                <labelfor='includeinscription'>Include Inscription($20)</label>
                <input type="checkBox" id="includeinscription" name="includeinscription" onclick="calculatetotal()" />
                <input type="text"  id="theinscription" name="theinscription" value="Enter Inscription"  />
                </p>
                <div id="totalPrice"></div>

解决方法:

如果将js代码移动到标题(或使用document.ready),它将起作用.另外,在HTML代码中应该有< form>标签工作……

小提琴演示:http://jsfiddle.net/sh7gfgj2/1/

(刚添加了表单标签,并在框架选项中将“onLoad”更改为“No wrap-in< head>”.)

我们今天的关于尝试做信用计算器,但总和不能正确添加的分享就到这里,谢谢您的阅读,如果想了解更多关于bash – 在python解释器提示符中添加颜色,不能正确包装、ggplot 位置堆栈未正确添加值、java – 如何正确添加侦听器以滑行、JavaScript费用计算器的相关信息,可以在本站进行搜索。

本文标签:

上一篇python abs函数中的数学计算(python中abs函数用法)

下一篇是否可以使用discord.py从您的计算机向消息中添加自定义反应图像文件?